home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume6 / dvi2tty-2 < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  88.8 KB

  1. Path: xanth!nic.MR.NET!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!allbery
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Newsgroups: comp.sources.misc
  4. Subject: v06i026: New version of DVI2TTY, now also for MSDOS
  5. Message-ID: <47758@uunet.UU.NET>
  6. Date: 29 Jan 89 21:18:50 GMT
  7. Sender: allbery@uunet.UU.NET
  8. Reply-To: mcvax!duteca!marcel@hal.CWRU.Edu (Marcel J.E. Mol)
  9. Organization: Delft University of Technology, Dep. of Electrotechnical engineering.
  10. Lines: 2441
  11. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  12. Organisation: University of Technology, Delft  The Netherlands.
  13. X-Arch-Keywords: c, dvi, portable
  14.  
  15. Posting-number: Volume 6, Issue 26
  16. Submitted-by: marcel@duteca.UUCP (Marcel J.E. Mol)
  17. Archive-name: dvi2tty-2
  18.  
  19. This is a new version of the DVI2TTY program posted a while ago.
  20. Many bugs are repaired (including the patch not posted by me).
  21.  
  22. Now it also runs on MSDOS.
  23.  
  24. Watch out: the shar file *does* overwrite existing files.
  25.  
  26. - Marcel
  27.  
  28. ####################### CUT HERE #######################
  29. #!/bin/sh
  30. # This is a shell archive, meaning:
  31. # 1. Remove everything above the #!/bin/sh line.
  32. # 2. Save the resulting text in a file.
  33. # 3. Execute the file with /bin/sh (not csh) to create the files:
  34. #     README         1695    bytes
  35. #     README.ORG         1051    bytes
  36. #     dvi2tty.1         4291    bytes
  37. #     Makefile          365    bytes
  38. #     commands.h         3506    bytes
  39. #     dvi2tty.h         3778    bytes
  40. #     disdvi.c        14807    bytes
  41. #     dvi2tty.c        23102    bytes
  42. #     dvistuff.c        31593    bytes
  43. # This archive created:  Wed Jan 25 20:20:27 MET 1989
  44. # By:     Marcel J.E. Mol
  45. export PATH
  46. echo shar: extracting README
  47. if test -f 'README'
  48. then
  49.     echo shar: over-writing existing file "'README'"
  50. fi
  51. sed -e 's/^-//' << \_E_O_F_ > README
  52. -                DVI2TTY
  53. -
  54. -
  55. -dvi2tty is intended for previewing dvi-files on text-only
  56. -devices (terminals and lineprinters).
  57. -The program is basicly an improved C version of the pascal
  58. -program written by Svante Lindahl (see README.ORG).
  59. -I translated it because I could not find a pascal compiler 
  60. -on our machine that could compile it.
  61. -The program runs under UNIX and MSDOS without problems
  62. -(you may need some site dependend redefinitions, see below).
  63. -Undocumented option: the -e option can be used to influence
  64. -the width of spaces. With a negative value the number of spaces 
  65. -between words becomes less, with a positive value it becomes more.
  66. -Just play around if you like, -e-11 worked nice with me.
  67. -
  68. -
  69. -                DVIDIS
  70. -
  71. -dvidis is a simple hack that dumps a dvi file in a more readable form.
  72. -It is not a spectacular program but use it and improve as you wish.
  73. -I'd appreciate any enhancements made, bug reports etc. mailed to me.
  74. -  
  75. -
  76. -    COMPILING THE PROGRAMS
  77. -
  78. -Dvidis is rather simple and does not need any modifications.
  79. -For dvi2tty you may find the following problems:
  80. -
  81. - function strchr() can not be found:
  82. -      Your are probably a BSD UNIX or alike.
  83. -      Solution: #define strchr index
  84. - '/usr/bin/pg' program not found.
  85. -      Solution: change the DEFPAGER macro in dvi2tty.c
  86. -
  87. -Thats all, good luck.
  88. -
  89. -
  90. -- Marcel 
  91. ------------------------------------------
  92. -| Marcel J.E. Mol                       | They hate you if your're clever
  93. -| Delft University of Technology        | And they despise the fool
  94. -| The Netherlands                       | Till you're so fucking crazy
  95. -| UUCP: marcel@duteca.UUCP              | You can't follow the rules.
  96. ------------------------------------------             - Lennon
  97. _E_O_F_
  98. if test 1695 -ne `wc -c < README `; then
  99.     echo shar: "'README'" unpacked with wrong size!
  100. fi
  101. echo shar: extracting README.ORG
  102. if test -f 'README.ORG'
  103. then
  104.     echo shar: over-writing existing file "'README.ORG'"
  105. fi
  106. sed -e 's/^-//' << \_E_O_F_ > README.ORG
  107. -
  108. -dvitty is intended for previewing dvi-files on text-only devices
  109. -(terminals and lineprinters). The output is not very pretty many
  110. -times, but it still saves quite a lot of work, especially if you
  111. -have a little ways to walk to a laserprinter, for example.
  112. -
  113. -The program was originally written in Hedrick-Pascal, running on
  114. -TOPS-20, and was later ported to UNIX (BSD, Berkeley-pascal).
  115. -
  116. -It is not very smart in all situations, but still serves it pur-
  117. -pose fairly well.
  118. -
  119. -For information on how to use see the man-page.
  120. -
  121. -Before compiling and installing inspect the  "compile-time cust-
  122. -omization constants" and change them to suit your site.
  123. -These constants configure default pager and a little more.
  124. -
  125. -Please report complaints, suggestions, bugs and/or fixes to:
  126. -
  127. -Svante Lindahl, NADA, KTH            Numerical Analysis & Computer Science 
  128. -UUCP: {seismo,mcvax}!enea!ttds!zap   Royal Institute of Technology, Sweden
  129. -ARPA: enea!ttds!zap@seismo.CSS.GOV   EAN: zap@cs.kth.sunet
  130. -
  131. -The TOPS-20 version of the program can also be obtained from the above
  132. -address.
  133. _E_O_F_
  134. if test 1051 -ne `wc -c < README.ORG `; then
  135.     echo shar: "'README.ORG'" unpacked with wrong size!
  136. fi
  137. echo shar: extracting dvi2tty.1
  138. if test -f 'dvi2tty.1'
  139. then
  140.     echo shar: over-writing existing file "'dvi2tty.1'"
  141. fi
  142. sed -e 's/^-//' << \_E_O_F_ > dvi2tty.1
  143. -.TH DVI2TTY Local "7 June 1986"
  144. -.SH NAME
  145. -dvi2tty \- preview a dvi\-file on an ordinary ascii terminal
  146. -.SH SYNOPSIS
  147. -.B dvi2tty
  148. -[ options ] dvi\-file
  149. -.SH DESCRIPTION
  150. -.I dvi2tty
  151. -converts a TeX DVI\-file to a format that is apprporiate for terminals
  152. -and lineprinters. The program is intended to be used for
  153. -preliminary proofreading of TeX-ed documents.
  154. -By default the output is directed to the terminal,
  155. -possibly through a pager (depending on how the program was installed),
  156. -but it can be directed to a file or a pipe.
  157. -.PP
  158. -The output leaves much to be desired, but is still
  159. -usefull if you want to avoid walking to the
  160. -laserprinter (or whatever) for each iteration of your
  161. -document.
  162. -.br
  163. -Since
  164. -.I dvi2tty
  165. -produces output for terminals and lineprinters the
  166. -representation of documents is naturally quite primitive.
  167. -Fontchanges are totally ignored, which implies that
  168. -special symbols, such as mathematical symbols, get mapped into the 
  169. -characters at the corresponding positions in the "standard" fonts.
  170. -.PP
  171. -If the width of the output text requires more columns than fits
  172. -in one line (c.f. the \-w option) it is broken into several lines by
  173. -.I dvi2tty
  174. -although they will be printed as one line on regular TeX output
  175. -devices (e.g.laserprinters). To show that a broken line is really
  176. -just one logical line an asterisk (``*'') in the last position
  177. -means that the logical line is continued on the next physical
  178. -line output by
  179. -.I dvi2tty.
  180. -Such a continuation line is started with a a space and an asterisk
  181. -in the first two columns.
  182. -.PP
  183. -Options may be specified in the environment variable DVI2TTY.
  184. -Any option on the commandline, conflicting with one in the
  185. -environment, will override the one from the environment.
  186. -.PP
  187. -.B Options:
  188. -.PP
  189. -.TP
  190. -.B \-o file
  191. -Write output to file ``file''.
  192. -.TP
  193. -.B \-p list
  194. -Print the pages chosen by list.
  195. -Numbers refer to TeX\-page numbers (known as \\count0).
  196. -An example of format for list is ``1,3:6,8''
  197. -to choose pages 1, 3 through 6 and 8.
  198. -Negative numbers can be used exactly as in TeX,
  199. -e g \-1 comes before \-4 as in ``\-p-1:-4,17''.
  200. -.TP
  201. -.B \-P list
  202. -Like \-p except that page numbers refer to
  203. -the sequential ordering of the pages in the dvi\-file.
  204. -Negative numbers don't make a lot of sense here...
  205. -.TP
  206. -.B \-w n
  207. -Specify terminal width
  208. -.I n.
  209. -Legal range 16\-132.
  210. -Default is 80. If your terminal has the
  211. -ability to display in 132 columns it might
  212. -be a good idea to use \-w132 and toggle the
  213. -terminal into this mode as output will
  214. -probably look somewhat better.
  215. -.TP
  216. -.B \-q
  217. -Don't pipe the output through a pager.
  218. -This may be the default on some systems
  219. -(depending on the whims of the SA installing the program).
  220. -.TP
  221. -.B \-f
  222. -Pipe through a pager, $PAGER if defined, or whatever your SA compiled
  223. -in (often ``more''). This may be the default, but it is still okay
  224. -to redirect output with ``>'', the pager will not be used if output
  225. -is not going to a terminal.
  226. -.TP
  227. -.B \-F
  228. -Specify the pager program to be used.
  229. -This overides the $PAGER and the default pager.
  230. -.TP
  231. -.B \-Fprog
  232. -Use ``prog'' as program to pipe output into. Can be used to choose an
  233. -alternate pager (e g ``-Fless'').
  234. -.TP
  235. -.B \-l
  236. -Mark pagebreaks with the two-character sequence ``^L''. The default is
  237. -to mark them with a formfeed character.
  238. -.TP
  239. -.B \-u
  240. -Don't make any attempts to find special Scandinavian characters.
  241. -If such characters are in the text they will map to ``a'' and ``o''.
  242. -This is probably the default outside of Scandinavia. (The SA made
  243. -the decision when  the program was installed.)
  244. -.TP
  245. -.B \-s
  246. -Try to find the special Scandinavian characters that on most (?)
  247. -terminals in Scandinavia are mapped to ``{|}[\\]''.
  248. -This can be the default, and output from files not containing these
  249. -special characters will be identical regardless of this option.
  250. -.SH FILES
  251. -/usr/ucb/more \ \ \ \ 
  252. -probably the default pager.
  253. -.SH ENVIRONMENT
  254. -PAGER \ \ \ \ \ \ \ \ \ \ \ \ 
  255. -the pager to use.
  256. -.br
  257. -DVI2TTY \ \ \ \ \ \ \ \ \ \ \ 
  258. -can be set to hold commandline options.
  259. -.SH "SEE ALSO"
  260. -TeX, dvi2ps
  261. -.SH AUTHOR
  262. -Svante Lindahl, Royal Institute of Technology, Stockholm
  263. -.br
  264. -Improved C version: Marcel Mol
  265. -.br
  266. -{seismo, mcvax}!enea!ttds!zap
  267. -.br
  268. -marcel@duteca.UUCP
  269. -.SH BUGS
  270. -Blanks between words get lost quite easy. This is less
  271. -likely if you are using a wider output than the default 80.
  272. -.PP
  273. -Only one file may be specified on the commandline.
  274. _E_O_F_
  275. if test 4291 -ne `wc -c < dvi2tty.1 `; then
  276.     echo shar: "'dvi2tty.1'" unpacked with wrong size!
  277. fi
  278. echo shar: extracting Makefile
  279. if test -f 'Makefile'
  280. then
  281.     echo shar: over-writing existing file "'Makefile'"
  282. fi
  283. sed -e 's/^-//' << \_E_O_F_ > Makefile
  284. -# Makefile for dvi2tty and disdvi       23/01/89   M.J.E. Mol
  285. -#
  286. -# For BSD Unix use the following CFLAGS definition
  287. -# CFLAGS = -Dstrchr=index
  288. -#
  289. -# This Makefile does not work for MSDOS. Make your 
  290. -# own one, or compile by hand.
  291. -#
  292. -CFLAGS = 
  293. -
  294. -all:    dvi2tty disdvi
  295. -
  296. -dvi2tty:dvi2tty.o dvistuff.o
  297. -    cc -o dvi2tty dvi2tty.o dvistuff.o
  298. -
  299. -disdvi:disdvi.o
  300. -    cc -o disdvi disdvi.o
  301. _E_O_F_
  302. if test 365 -ne `wc -c < Makefile `; then
  303.     echo shar: "'Makefile'" unpacked with wrong size!
  304. fi
  305. echo shar: extracting commands.h
  306. if test -f 'commands.h'
  307. then
  308.     echo shar: over-writing existing file "'commands.h'"
  309. fi
  310. sed -e 's/^-//' << \_E_O_F_ > commands.h
  311. -/* DVI COMMANDS */
  312. -#define  SETC_000         0     /* typeset character 0 and move right */
  313. -#define  SETC_127       127     /* typeset character 127 and move right */
  314. -#define  SET1           128     /* typeset a character and move right */
  315. -#define  SET2           129     /* ??? */
  316. -#define  SET3           130     /* ??? */
  317. -#define  SET4           131     /* ??? */
  318. -#define  SET_RULE       132     /* typeset a rule and move right */
  319. -#define  PUT1           133     /* typeset a character */
  320. -#define  PUT2           134     /* ??? */
  321. -#define  PUT3           135     /* ??? */
  322. -#define  PUT4           136     /* ??? */
  323. -#define  PUT_RULE       137     /* typeset a rule */
  324. -#define  NOP            138     /* no operation */
  325. -#define  BOP            139     /* beginning of page */
  326. -#define  EOP            140     /* ending of page */
  327. -#define  PUSH           141     /* save the current positions */
  328. -#define  POP            142     /* restore previous positions */
  329. -#define  RIGHT1         143     /* move right */
  330. -#define  RIGHT2         144     /* ??? */
  331. -#define  RIGHT3         145     /* ??? */
  332. -#define  RIGHT4         146     /* ??? */
  333. -#define  W0             147     /* move right by |w| */
  334. -#define  W1             148     /* move right and set |w| */
  335. -#define  W2             149     /* ??? */
  336. -#define  W3             150     /* ??? */
  337. -#define  W4             151     /* ??? */
  338. -#define  X0             152     /* move right by |x| */
  339. -#define  X1             153     /* move right and set |x| */
  340. -#define  X2             154     /* ??? */
  341. -#define  X3             155     /* ??? */
  342. -#define  X4             156     /* ??? */
  343. -#define  DOWN1          157     /* move down */
  344. -#define  DOWN2          158     /* ??? */
  345. -#define  DOWN3          159     /* ??? */
  346. -#define  DOWN4          160     /* ??? */
  347. -#define  Y0             161     /* move down by |y| */
  348. -#define  Y1             162     /* move down and set |y| */
  349. -#define  Y2             163     /* ??? */
  350. -#define  Y3             164     /* ??? */
  351. -#define  Y4             165     /* ??? */
  352. -#define  Z0             166     /* move down by |z| */
  353. -#define  Z1             167     /* move down and set |z| */
  354. -#define  Z2             168     /* ??? */
  355. -#define  Z3             169     /* ??? */
  356. -#define  Z4             170     /* ??? */
  357. -#define  FONT_00        171     /* set current font to 0 */
  358. -#define  FONT_63        234     /* set current font to 0 */
  359. -#define  FNT1           235     /* set current font */
  360. -#define  FNT2           236     /* Same as FNT1, except that arg is 2 bytes */
  361. -#define  FNT3           237     /* Same as FNT1, except that arg is 3 bytes */
  362. -#define  FNT4           238     /* Same as FNT1, except that arg is 4 bytes */
  363. -#define  XXX1           239     /* extension to \.DVI primitives */
  364. -#define  XXX2           240     /* Like XXX1, but 0<=k<65536 */
  365. -#define  XXX3           241     /* Like XXX1, but 0<=k<@t$2^{24}$@> */
  366. -#define  XXX4           242     /* potentially long extension to \.DVI
  367. -                                   primitives */
  368. -#define  FNT_DEF1       243     /* define the meaning of a font number */
  369. -#define  FNT_DEF2       244     /* ??? */
  370. -#define  FNT_DEF3       245     /* ??? */
  371. -#define  FNT_DEF4       246     /* ??? */
  372. -#define  PRE            247     /* preamble */
  373. -#define  POST           248     /* postamble beginning */
  374. -#define  POST_POST      249     /* postamble ending */
  375. -#define  TRAILER        223     /* trailer bytes in dvi file */
  376. -
  377. -        /*  undefined_commands           250,251,252,253,254,255 */
  378. _E_O_F_
  379. if test 3506 -ne `wc -c < commands.h `; then
  380.     echo shar: "'commands.h'" unpacked with wrong size!
  381. fi
  382. echo shar: extracting dvi2tty.h
  383. if test -f 'dvi2tty.h'
  384. then
  385.     echo shar: over-writing existing file "'dvi2tty.h'"
  386. fi
  387. sed -e 's/^-//' << \_E_O_F_ > dvi2tty.h
  388. -#define Copyright "dvi2tty.c  Copyright (C) 1984, 1985, 1986 Svante Lindahl.\n\
  389. -Copyright (C) 1988 M.J.E. Mol"
  390. -
  391. -#include <stdio.h>
  392. -#if defined(MSDOS)
  393. -#include <stdlib.h>
  394. -#include <string.h>
  395. -#include <malloc.h>
  396. -#endif
  397. -
  398. -#define TRUE        1
  399. -#define FALSE       0
  400. -#define nil         NULL
  401. -
  402. -/*
  403. - * ERROR CODES , don't start with 0
  404. - */
  405. -
  406. -#define illop    1              /* illegal op-code                   */
  407. -#define stkof    2              /* stack over-flow                   */
  408. -#define stkuf    3              /* stack under-flow                  */
  409. -#define stkrq    4              /* stack requirement                 */
  410. -#define lnerq    5              /* line allocation                   */
  411. -#define badid    6              /* id is not right                   */
  412. -#define bdsgn    7              /* signature is wrong                */
  413. -#define fwsgn    8              /* too few signatures                */
  414. -#define nopre    9              /* no pre-amble where expected       */
  415. -#define nobop   10              /* no bop-command where expected     */
  416. -#define nopp    11              /* no postpost where expected        */
  417. -#define bdpre   12              /* unexpected preamble occured       */
  418. -#define bdbop   13              /* unexpected bop-command occured    */
  419. -#define bdpst   14              /* unexpected post-command occured   */
  420. -#define bdpp    15              /* unexpected postpost               */
  421. -#define nopst   16              /* no post-amble where expected      */
  422. -#define illch   17              /* character code out of range       */
  423. -#define filop   18              /* cannot access file                */
  424. -#define filcr   19              /* cannot creat file                 */
  425. -#if !defined(MSDOS)
  426. -#define pipcr   20              /* cannot creat pipe                 */
  427. -#endif
  428. -
  429. -/*---------------------------------------------------------------------------*/
  430. -
  431. -typedef char bool;
  432. -
  433. -typedef struct prlistptr {      /* list of pages selected for output         */
  434. -    int       pag;                      /* number of pages                   */
  435. -    bool      all;                      /* pages in interval selected        */
  436. -    struct prlistptr *prv;              /* previous item in list             */
  437. -    struct prlistptr *nxt;              /* next item in list                 */
  438. -} printlisttype;
  439. -
  440. -/*---------------------------------------------------------------------------*/
  441. -
  442. -extern bool   outputtofile;            /* output to file or stdout(dvi2tty.c)*/
  443. -extern bool   pageswitchon;            /* user-set pages to print(dvistuff.c)*/
  444. -extern bool   sequenceon;              /* not TeX pagenrs (dvistuff.c)       */
  445. -extern bool   scascii;                 /* Scand. nat. chars (dvistuff.c)     */
  446. -extern bool   noffd;                   /* output ^L or formfeed (dvistuff.c) */
  447. -
  448. -extern printlisttype *currentpage;     /* current page to print (dvi2tty.c)  */
  449. -extern printlisttype *firstpage;       /* first page selected (dvi2tty.c)    */
  450. -extern printlisttype *lastpage;        /* last page selected (dvi2tty.c)     */
  451. -
  452. -extern int            ttywidth;        /* screen width (dvi2tty.c)           */
  453. -extern int            espace;          /* extra screen width (dvi2tty.c)     */
  454. -extern long           foo;             /* temporary 'register' (dvi2tty.c)   */
  455. -extern int            opcode;          /* dvi opcode (dvistuff.c)            */
  456. -
  457. -extern FILE *DVIfile;                  /* dvi file (dvi2tty.c)               */
  458. -extern FILE *output;                   /* output file (dvi2tty.c)            */
  459. -
  460. -/*---------------------------------------------------------------------------*/
  461. -
  462. -/* dvi2tty.c */
  463. -#if defined(MSDOS)
  464. -void errorexit(int);
  465. -#else
  466. -void errorexit();
  467. -#endif
  468. -
  469. -/* dvistuff.c */
  470. -#if defined(MSDOS)
  471. -void dvimain(void);
  472. -#else
  473. -void dvimain();
  474. -#endif
  475. _E_O_F_
  476. if test 3778 -ne `wc -c < dvi2tty.h `; then
  477.     echo shar: "'dvi2tty.h'" unpacked with wrong size!
  478. fi
  479. echo shar: extracting disdvi.c
  480. if test -f 'disdvi.c'
  481. then
  482.     echo shar: over-writing existing file "'disdvi.c'"
  483. fi
  484. sed -e 's/^-//' << \_E_O_F_ > disdvi.c
  485. -/*****************************************************************************/
  486. -/*                                                                           */
  487. -/*   disdvi  ---  disassembles TeX dvi files.                                */
  488. -/*                                                                           */
  489. -/*****************************************************************************/
  490. -
  491. -#include <stdio.h>
  492. -#include <ctype.h>
  493. -#include "commands.h"
  494. -#if defined(MSDOS)
  495. -#include <stdlib.h>
  496. -#include <string.h>
  497. -#include <fcntl.h>
  498. -#endif
  499. -
  500. -#define LASTCHAR        127    /* max dvi character, above are commands    */
  501. -
  502. -#define get1()           num(1)
  503. -#define get2()           num(2)
  504. -#define get3()           num(3)
  505. -#define get4()           num(4)
  506. -#define sget1()         snum(1)
  507. -#define sget2()         snum(2)
  508. -#define sget3()         snum(3)
  509. -#define sget4()         snum(4)
  510. -
  511. -
  512. -FILE * dvifp;
  513. -char * dvi_name;
  514. -long   pc = 0;
  515. -
  516. -char *          malloc          ();
  517. -
  518. -void            main            ();
  519. -void            bop             ();
  520. -void            preamble        ();
  521. -void            postamble       ();
  522. -void            postpostamble   ();
  523. -void            fontdef         ();
  524. -void            special         ();
  525. -void            printnonprint   ();
  526. -unsigned long   num             ();
  527. -long            snum            ();
  528. -
  529. -
  530. -
  531. -
  532. -/*---------------------------------------------------------------------------*/
  533. -
  534. -void main(argc, argv)
  535. -int argc;
  536. -char **argv;
  537. -{
  538. -    register int opcode;                /* dvi opcode                        */
  539. -    register int i;
  540. -
  541. -    if (argc > 2) {
  542. -        fprintf(stderr, "To many arguments\n");
  543. -        fprintf(stderr, "Usage: %s [dvi-file]\n", *argv);
  544. -        exit(1);
  545. -    }
  546. -
  547. -    if (argc == 2) {
  548. -        if ((i = strlen(argv[1])) == 0) {
  549. -            fprintf(stderr, "Illegal empty filename\n");
  550. -            fprintf(stderr, "Usage: %s [dvi-file]\n", *argv);
  551. -            exit(2);
  552. -        }
  553. -        if ((i >= 5) && (argv[1][i-4] == '.') && (argv[1][i-3] == 'd') &&
  554. -              (argv[1][i-2] = 'v') && (argv[1][i-1] = 'i'))
  555. -            dvi_name = argv[1];
  556. -        else {
  557. -            dvi_name = malloc((i+4) * sizeof(char));
  558. -            strcpy(dvi_name, argv[1]);
  559. -            strcat(dvi_name, ".dvi");
  560. -        }
  561. -        if ((dvifp = fopen(dvi_name, "r")) == NULL) {
  562. -            perror(dvi_name);
  563. -            exit(3);
  564. -        }
  565. -    }
  566. -    else
  567. -        dvifp = stdin;
  568. -
  569. -#if defined(MSDOS)
  570. -    setmode(fileno(dvifp), O_BINARY);
  571. -#endif
  572. -
  573. -    while ((opcode = (int) get1()) != EOF) {    /* process until end of file */
  574. -        printf("%06ld: ", pc - 1);
  575. -        if ((opcode <= LASTCHAR) && isprint(opcode)) {
  576. -            printf("Char:     ");
  577. -            while ((opcode <= LASTCHAR) && isprint(opcode)) {
  578. -                putchar(opcode);
  579. -                opcode = (int) get1();
  580. -            }
  581. -            putchar('\n');
  582. -            printf("%06ld: ", pc - 1);
  583. -        }
  584. -
  585. -        if (opcode <= LASTCHAR) 
  586. -            printnonprint(opcode);              /* it must be a non-printable */
  587. -        else if ((opcode >= FONT_00) && (opcode <= FONT_63))
  588. -            printf("FONT_%d\n", opcode - FONT_00);
  589. -        else
  590. -            switch (opcode) {
  591. -                case SET1     :
  592. -                case SET2     : 
  593. -                case SET3     :
  594. -                case SET4     : printf("SET%d:    %ld\n", opcode - SET1 + 1,
  595. -                                                       num(opcode - SET1 + 1));
  596. -                                break;
  597. -                case SET_RULE : printf("SET_RULE: %ld, %ld\n", sget4(),
  598. -                                                                sget4());
  599. -                                break;
  600. -                case PUT1     :
  601. -                case PUT2     :
  602. -                case PUT3     :
  603. -                case PUT4     : printf("PUT%d:     %ld\n", opcode - PUT1 + 1,
  604. -                                                       num(opcode - PUT1 + 1));
  605. -                                break;
  606. -                case PUT_RULE : printf("PUT_RULE: %ld, %ld\n", sget4(),
  607. -                                                                sget4());
  608. -                                break;
  609. -                case NOP      : printf("NOP\n");  break;
  610. -                case BOP      : bop();            break;
  611. -                case EOP      : printf("EOP\n");  break;
  612. -                case PUSH     : printf("PUSH\n"); break;
  613. -                case POP      : printf("POP\n");  break;
  614. -                case RIGHT1   :
  615. -                case RIGHT2   : 
  616. -                case RIGHT3   : 
  617. -                case RIGHT4   : printf("RIGHT%d:   %ld\n", opcode - RIGHT1 + 1,
  618. -                                                     snum(opcode - RIGHT1 + 1));
  619. -                                break;
  620. -                case W0       : printf("W0\n");   break;
  621. -                case W1       : 
  622. -                case W2       :
  623. -                case W3       :
  624. -                case W4       : printf("W%d:       %ld\n", opcode - W0,
  625. -                                                      snum(opcode - W0));
  626. -                                break;
  627. -                case X0       : printf("X0\n");   break;
  628. -                case X1       :
  629. -                case X2       :
  630. -                case X3       :
  631. -                case X4       : printf("X%d:       %ld\n", opcode - X0,
  632. -                                                      snum(opcode - X0));
  633. -                                break;
  634. -                case DOWN1    : 
  635. -                case DOWN2    : 
  636. -                case DOWN3    :
  637. -                case DOWN4    : printf("DOWN%d:    %ld\n", opcode - DOWN1 + 1,
  638. -                                                      snum(opcode - DOWN1 + 1));
  639. -                                break;
  640. -                case Y0       : printf("Y0\n");   break;
  641. -                case Y1       :
  642. -                case Y2       :
  643. -                case Y3       :
  644. -                case Y4       : printf("Y%d:       %ld\n", opcode - Y0,
  645. -                                                      snum(opcode - Y0));
  646. -                                break;
  647. -                case Z0       : printf("Z0\n");   break;
  648. -                case Z1       :
  649. -                case Z2       :
  650. -                case Z3       : 
  651. -                case Z4       : printf("Z%d:       %ld\n", opcode - Z0,
  652. -                                                      snum(opcode - Z0));
  653. -                                break;
  654. -                case FNT1     :
  655. -                case FNT2     :
  656. -                case FNT3     :
  657. -                case FNT4     : printf("FNT%d:     %ld\n", opcode - FNT1 + 1,
  658. -                                                       num(opcode - FNT1 + 1));
  659. -                                break;
  660. -                case XXX1     : 
  661. -                case XXX2     : 
  662. -                case XXX3     :
  663. -                case XXX4     : special(opcode - XXX1 + 1);     break;
  664. -                case FNT_DEF1 :
  665. -                case FNT_DEF2 :
  666. -                case FNT_DEF3 :
  667. -                case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); break;
  668. -                case PRE      : preamble();                     break;
  669. -                case POST     : postamble();                    break;
  670. -                case POST_POST: postpostamble();                break;
  671. -            }
  672. -    }
  673. -
  674. -} /* main */
  675. -
  676. -
  677. -/*----------------------------------------------------------------------------*/
  678. -
  679. -
  680. -void bop()
  681. -{
  682. -    int i;
  683. -
  684. -    printf("BOP       page number      : %ld\n", sget4());
  685. -    for (i=0; i < 3; i++) {
  686. -        printf("%06ld: ", pc - 1);
  687. -        printf("          %6ld  %6ld  %6ld\n", sget4(), sget4(), sget4()); 
  688. -    }
  689. -    printf("%06ld: ", pc - 1);
  690. -    printf("          prev page offset : %06ld\n", sget4()); 
  691. -
  692. -} /* bop */
  693. -
  694. -
  695. -/*---------------------------------------------------------------------------*/
  696. -
  697. -void postamble() 
  698. -{
  699. -
  700. -    printf("POST      last page offset : %06ld\n", sget4());
  701. -    printf("%06ld: ", pc - 1);
  702. -    printf("          numerator        : %ld\n", get4());
  703. -    printf("%06ld: ", pc - 1);
  704. -    printf("          denominator      : %ld\n", get4());
  705. -    printf("%06ld: ", pc - 1);
  706. -    printf("          magnification    : %ld\n", get4());
  707. -    printf("%06ld: ", pc - 1);
  708. -    printf("          max page height  : %ld\n", get4());
  709. -    printf("%06ld: ", pc - 1);
  710. -    printf("          max page width   : %ld\n", get4());
  711. -    printf("%06ld: ", pc - 1);
  712. -    printf("          stack size needed: %d\n", (int) get2());
  713. -    printf("%06ld: ", pc - 1);
  714. -    printf("          number of pages  : %d\n", (int) get2());
  715. -
  716. -} /* postamble */
  717. -
  718. -void preamble()
  719. -{
  720. -    register int i;
  721. -
  722. -    printf("PRE       version          : %d\n", (int) get1());
  723. -    printf("%06ld: ", pc - 1);
  724. -    printf("          numerator        : %ld\n", get4());
  725. -    printf("%06ld: ", pc - 1);
  726. -    printf("          denominator      : %ld\n", get4());
  727. -    printf("%06ld: ", pc - 1);
  728. -    printf("          magnification    : %ld\n", get4());
  729. -    printf("%06ld: ", pc - 1);
  730. -    i = (int) get1();
  731. -    printf("          job name (%03d)   :", i);
  732. -    while (i-- > 0)
  733. -        putchar((int) get1());
  734. -    putchar('\n');
  735. -
  736. -} /* preamble */
  737. -
  738. -
  739. -void postpostamble()
  740. -{
  741. -    register int i;
  742. -    printf("POSTPOST  postamble offset : %06ld\n", get4());
  743. -    printf("%06ld: ", pc - 1);
  744. -    printf("          version          : %d\n", (int) get1());
  745. -    while ((i = (int) get1()) == TRAILER) {
  746. -        printf("%06d: ", pc - 1);
  747. -        printf("TRAILER\n");
  748. -    }
  749. -    while (i != EOF) {
  750. -        printf("%06ld: ", pc - 1);
  751. -        printf("BAD DVI FILE END: 0x%02X\n", i);
  752. -        i = (int) get1();
  753. -    }
  754. -
  755. -} /* postpostamble */
  756. -
  757. -
  758. -
  759. -void special(x)
  760. -register int x;
  761. -{
  762. -    register long len;
  763. -    register long i;
  764. -
  765. -    len = num(x);
  766. -    printf("XXX%d:     %ld bytes\n", x, len);
  767. -    printf("%06ld: ", pc - 1);
  768. -    for (i = 0; i < len; i++)
  769. -        putchar((int) get1());
  770. -    putchar('\n');
  771. -
  772. -} /* special */
  773. -
  774. -
  775. -
  776. -void fontdef(x)
  777. -register int x;
  778. -{
  779. -    register int i;
  780. -
  781. -    printf("FNT_DEF%d: %ld\n", x, num(x));
  782. -    printf("%06ld: ", pc - 1);
  783. -    printf("          checksum         : %ld\n", get4());
  784. -    printf("%06ld: ", pc - 1);
  785. -    printf("          scale            : %ld\n", get4());
  786. -    printf("%06ld: ", pc - 1);
  787. -    printf("          design           : %ld\n", get4());
  788. -    printf("%06ld: ", pc - 1);
  789. -    printf("          name             : ");
  790. -    for (i = (int) get1() + (int) get1(); i > 0; i--)
  791. -        putchar((int) get1());
  792. -    putchar('\n');
  793. -
  794. -} /* fontdef */
  795. -
  796. -
  797. -
  798. -void printnonprint(ch)
  799. -register int ch;
  800. -{
  801. -
  802. -    printf("Char:     ");
  803. -    switch (ch) {
  804. -        case 11  :  printf("ff         /* ligature (non-printing) */"); break;
  805. -        case 12  :  printf("fi         /* ligature (non-printing) */"); break;
  806. -        case 13  :  printf("fl         /* ligature (non-printing) */"); break;
  807. -        case 14  :  printf("ffi        /* ligature (non-printing) */"); break;
  808. -        case 15  :  printf("ffl        /* ligature (non-printing) */"); break;
  809. -        case 16  :  printf("i          /* (non-printing) */");          break;
  810. -        case 17  :  printf("j          /* (non-printing) */");          break;
  811. -        case 25  :  printf("ss         /* german (non-printing) */");   break;
  812. -        case 26  :  printf("ae         /* scadinavian (non-printing) */");
  813. -                    break;
  814. -        case 27  :  printf("oe         /* scadinavian (non-printing) */");
  815. -                    break;
  816. -        case 28  :  printf("o          /* scadinavian (non-printing) */");
  817. -                    break;
  818. -        case 29  :  printf("AE         /* scadinavian (non-printing) */");
  819. -                    break;
  820. -        case 30  :  printf("OE         /* scadinavian (non-printing) */");
  821. -                    break;
  822. -        case 31  :  printf("O          /* scadinavian (non-printing) */");
  823. -                    break;
  824. -        default  :  printf("0x%2X", ch); break;
  825. -    }
  826. -    putchar('\n');
  827. -
  828. -}
  829. -
  830. -
  831. -
  832. -unsigned long num(size)
  833. -register int size;
  834. -{
  835. -    register int i;
  836. -    register long x = 0;
  837. -
  838. -    pc += size;
  839. -    for (i = 0; i < size; i++)
  840. -        x = (x << 8) + (unsigned) getc(dvifp);
  841. -    return x;
  842. -
  843. -} /* num */
  844. -
  845. -
  846. -
  847. -long snum(size)
  848. -register int size;
  849. -{
  850. -    register int i;
  851. -    register long x = 0;
  852. -
  853. -    pc += size;
  854. -    x = getc(dvifp);
  855. -    if (x & 0x80)
  856. -        x -= 0x100;
  857. -    for (i = 1; i < size; i++)
  858. -        x = (x << 8) + (unsigned) getc(dvifp);
  859. -    return x;
  860. -
  861. -} /* snum */
  862. -
  863. -
  864. -
  865. -/*
  866. -
  867. -
  868. -================================================================================
  869. -==                          DVI file format                                   ==
  870. -================================================================================
  871. -no_ops          >= 0 bytes     (NOP, nops before the preamble)
  872. -preamble_marker    1 ubyte     (PRE)
  873. -version_id         1 ubyte     (should be version 2)
  874. -numerator          4 ubytes    (numerater must equal the one in postamble)
  875. -denominator        4 ubytes    (denominator must equal the one in postamble)
  876. -magnification      4 ubytes    (magnification must equal the one in postamble)
  877. -id_len             1 ubyte     (lenght of identification string)
  878. -id_string     id_len ubytes    (identification string)
  879. -
  880. -no_ops          >= 0 bytes     (NOP, nops before a page)
  881. -begin_of_page      1 ubyte     (BOP)
  882. -page_nr            4 sbytes    (page number)
  883. -do_be_do          36 bytes     (filler ????)
  884. -prev_page_offset   4 sbytes    (offset in file where previous page starts, -1 for none)
  885. -... PAGE DATA ...
  886. -end_of_page        1 ubyte     (EOP)
  887. -
  888. -no_ops ???      >= 0 bytes     (NOPS, I think they are allowed here...)
  889. -postamble_marker   1 ubyte     (POST)
  890. -last_page_offset   4 sbytes    (offset in file where last page starts)
  891. -numerator          4 ubytes    (numerater must equal the one in preamble)
  892. -denominator        4 ubytes    (denominator must equal the one in preamble)
  893. -magnification      4 ubytes    (magnification must equal the one in preamble)
  894. -max_page_height    4 ubytes    (maximum page height)
  895. -max_page_width     4 ubytes    (maximum page width)
  896. -max_stack          2 ubytes    (maximum stack depth needed)
  897. -total_pages        2 ubytes    (number of pages in file)
  898. -... FONT DEFINITIONS ...
  899. -
  900. -postamble_offset   4 sbytes    (offset in file where postamble starts)
  901. -version_id         1 ubyte     (should be version 2)
  902. -trailer         >= 4 ubytes    (TRAILER)
  903. -<EOF>
  904. -
  905. -
  906. -FONT DEFINITIONS:
  907. -   do {
  908. -      switch (c = getc(dvi_fp) {
  909. -          case FNTDEF1  :
  910. -          case FNTDEF2  :
  911. -          case FNTDEF3  :
  912. -          case FNTDEF4  :  define_font(c);
  913. -          case POSTPOST : break;
  914. -          default       : error;
  915. -      }
  916. -   } while (c != POSTPOST);
  917. -
  918. -===== A font def looks like:
  919. -
  920. -1,2,3 or 4 ubytes TeXfontnumber for FNTDEF1 .. FNTDEF4
  921. -4 ubytes checksum
  922. -4 ubytes scale
  923. -4 ubytes design size
  924. -1 byte deflen1
  925. -1 byte deflen2
  926. -deflen1 + deflen2 bytes fontname.
  927. -
  928. -===== A special looks like:
  929. -
  930. -1,2,3 or 4 ubytes telling length of special command for XXX1 .. XXX4
  931. -all bytes in the special command are used as defined in the dvi driver.
  932. -
  933. -
  934. -*/
  935. _E_O_F_
  936. if test 14807 -ne `wc -c < disdvi.c `; then
  937.     echo shar: "'disdvi.c'" unpacked with wrong size!
  938. fi
  939. echo shar: extracting dvi2tty.c
  940. if test -f 'dvi2tty.c'
  941. then
  942.     echo shar: over-writing existing file "'dvi2tty.c'"
  943. fi
  944. sed -e 's/^-//' << \_E_O_F_ > dvi2tty.c
  945. -/******************************************************************************
  946. - * Marcel Mol: 1989-01-19  (UUCP: duteca!marcel)
  947. - *               Changed in option handling, no change
  948. - *               in user interface (only the undocumented 
  949. - *               feature -e).
  950. - *               Version 3.1.
  951. - * Marcel Mol: 1989-01-11  (UUCP: duteca!marcel)
  952. - *               Changed some longs to ints.
  953. - *               It now also runs on MSDOS Microsoft C 5.1
  954. - *               New version: 3.0
  955. - * Marcel Mol: 1989-01-03  (UUCP: duteca!marcel)
  956. - *               Fixed a bugs concerning pager programs
  957. - *               and scanning environment variable DVI2TTY.
  958. - * Marcel Mol: 1988-10-25  (UUCP: duteca!marcel)
  959. - *        dvi2tty.c dvi2tty.h dvistuff.c commands.h
  960. - *               Converted program to C.
  961. - *               improved spacing between words/characters.
  962. - * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-08-15 20:24:31,
  963. - *               Version to be sent to mod.sources ready.
  964. - * New option since last version:
  965. - *   -Fprog      Pipe output to prog. Can be used to get a different
  966. - *               pager than the default.
  967. - * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-13 21:49:31,
  968. - *   Environment variable DVITTY is read and options can be set from it.
  969. - *   These are the currently implemented options:
  970. - *      -ofile   Write output to file, else write to stdout,
  971. - *               possibly piped through a pager if stdout is a tty.
  972. - *      -plist   Print pages whos TeX-page-number are in list.
  973. - *               List is on the form  1,3:6,8  to choose pages
  974. - *               1,3-6 and 8. TeX-nrs can be negative: -p-1:-4,4
  975. - *      -Plist   Print pages whos sequential number are in list.
  976. - *      -wn      Print the lines with width n characters, default is
  977. - *               80. Wider lines gives better results.
  978. - *      -q       Don't try to pipe to a pager.
  979. - *      -f       Try to pipe to a pager if output is a tty.
  980. - *      -Fname   Specify a pager program.                  
  981. - *               Default of -q and -f is a compile time option, a constant.
  982. - *      -l       Write '^L' instead of formfeed between pages.
  983. - *      -u       Don't try to find Scandinavian characters (they will
  984. - *               print as a:s and o:s if this option is choosen).
  985. - *      -s       Scandinavian characters printed as }{|][\.
  986. - *               Default of -s and -u is a compile time option, a constant.
  987. - * bogart:/usr/alla/zap/dvitty/dvitty.p  1986-01-10 18:51:03,
  988. - *   Argument parsing, and random access functions (external, in C)
  989. - *   and other OS-dependent stuff (in C). Removed private 'pager' &
  990. - *   tries to pipe through PAGER (environment var) or, if PAGER not
  991. - *   defined, /usr/ucb/more. Some changes for efficency.
  992. - * bogart:/usr/alla/svante/dvitty/dvitty.p  1985-07-15 20:51:00,
  993. - *   The code for processing dvi-files running on UNIX (UCB-Pascal)
  994. - *   but no argument parsing.
  995. - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.140, 30-Mar-85 05:43:56,
  996. - *   Edit: Svante Lindahl
  997. - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.136, 15-Jan-85 13:52:59,
  998. - *   Edit: Svante Lindahl, final Twenex version !!!??
  999. - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.121, 14-Jan-85 03:10:22,
  1000. - *   Edit: Svante Lindahl, cleaned up and fixed a lot of little things
  1001. - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.25, 15-Dec-84 05:29:56,
  1002. - *   Edit: Svante Lindahl, COMND-interface, including command line scanning
  1003. - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.23, 10-Dec-84 21:24:41,
  1004. - *   Edit: Svante Lindahl, added command line scanning with Rscan-JSYS
  1005. - * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.48,  8-Oct-84 13:26:30,
  1006. - *  Edit: Svante Lindahl, fixed switch-parsing, destroyed by earlier patches
  1007. - * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.45, 29-Sep-84 18:29:53,
  1008. - *  Edit: Svante Lindahl
  1009. - *
  1010. - * dvitty - get an ascii representation of a dvi-file, suitable for ttys
  1011. - *
  1012. - * This program, and any documentation for it, is copyrighted by Svante
  1013. - * Lindahl. It may be copied for non-commercial use only, provided that
  1014. - * any and all copyright notices are preserved.
  1015. - *
  1016. - * Please report any bugs and/or fixes to:
  1017. - *
  1018. - * UUCP: {seismo,mcvax,cernvax,diku,ukc,unido}!enea!ttds!zap
  1019. - * ARPA: enea!ttds!zap@seismo.CSS.GOV
  1020. - *  or   Svante_Lindahl_NADA%QZCOM.MAILNET@MIT-MULTICS.ARPA
  1021. - * EAN:  zap@cs.kth.sunet
  1022. - */
  1023. -
  1024. -
  1025. -#include "dvi2tty.h"
  1026. -
  1027. -    /*-----------------------------------------------------------------------*/
  1028. -    /* The following constants may be toggled before compilation to          */
  1029. -    /* customize the default behaviour of the program for your site.         */
  1030. -    /* Whichever their settings are, the defaults can be overridden at       */
  1031. -    /* runtime.                                                              */
  1032. -    /*-----------------------------------------------------------------------*/
  1033. -
  1034. -#define DEFSCAND    FALSE     /* default is Scandinavian, toggle this if you */
  1035. -                              /* don't have terminals with Scand. nat. chars */
  1036. -#define WANTPAGER   TRUE      /* default: try to pipe through a pager (like  */
  1037. -                              /* more) if stdout is tty and no -o switch     */
  1038. -#define DEFPAGER    "/usr/bin/pg"   /* CHANGE TO YOUR LOCAL PAGER            */
  1039. -
  1040. -    /*------------------ end of customization constants ---------------------*/
  1041. -
  1042. -#define MAXLEN          100    /* size of char-arrays for strings            */
  1043. -#if defined(MSDOS)
  1044. -#define OPTSET      "wepPousl"   /* legal options                            */
  1045. -#define OPTWARG     "wepPo"      /* options with argument                    */
  1046. -#else
  1047. -#define OPTSET      "wepPousqlfF"/* legal options                            */
  1048. -#define OPTWARG     "wepPoF"     /* options with argument                    */
  1049. -#endif
  1050. -
  1051. -/*
  1052. - * USAGE CODES
  1053. - */
  1054. -
  1055. -#define wrnge  1                /* width switch arg out of range     */
  1056. -#define ign    2                /* ignore cause, print 'Usage:..'    */
  1057. -#define nan    3                /* not a number where one expected   */
  1058. -#define gae    4                /* garbage at end                    */
  1059. -#define bdlst  5                /* bad page-numberlist               */
  1060. -#define onef   6                /* only one dvifile allowed          */
  1061. -#define bdopt  7                /* bad option                        */
  1062. -#define onepp  8                /* only one page list allowed        */
  1063. -#define noarg  9                /* argument expected                 */
  1064. -
  1065. -char *dvi2tty = "(#)@  dvi2tty.c  3.1 23/01/89 M.J.E. Mol (c) 1989"
  1066. -
  1067. -/*---------------------------------------------------------------------------*/
  1068. -
  1069. -printlisttype * currentpage;    /* current page to print                     */
  1070. -printlisttype * firstpage;      /* first page selected                       */
  1071. -printlisttype * lastpage;       /* last page selected                        */
  1072. -
  1073. -FILE *          DVIfile;
  1074. -FILE *          output;
  1075. -bool            outputtofile;   /* tells if output goes to file or stdout    */
  1076. -int             ttywidth;       /* max nr of chars per printed line          */
  1077. -int             espace;         /* to fake calcs with ttywidth               */
  1078. -
  1079. -long            foo;            /* utility variable, "register"              */
  1080. -#if !defined(MSDOS)
  1081. -bool            pager;          /* tells if output is piped to a pager       */
  1082. -char  *         path;           /* name of the pager to run                  */
  1083. -#endif
  1084. -char  *         progname;       /* our name                                  */
  1085. -int             Argc;
  1086. -char **         Argv;
  1087. -char            DVIfilename[MAXLEN];
  1088. -char *          OUTfilename;
  1089. -char            optch;          /* for option handling                       */
  1090. -
  1091. -/*---------------------------------------------------------------------------*/
  1092. -
  1093. -#if defined(MSDOS)
  1094. -void    main      (int, char **); 
  1095. -void    setoption (char *);
  1096. -void    getargs   (void);
  1097. -void    getpages  (int, char *);
  1098. -void    plcnxt    (int);
  1099. -void    getname   (char *);
  1100. -int     getinteger(int *, int *, char *);
  1101. -void    usage     (int);
  1102. -#else
  1103. -char *  getenv    ();
  1104. -FILE *  popen     ();
  1105. -
  1106. -void    main      (); 
  1107. -void    setoption ();
  1108. -void    getargs   ();
  1109. -void    getpages  ();
  1110. -void    plcnxt    ();
  1111. -void    getname   ();
  1112. -int     getinteger();
  1113. -void    usage     ();
  1114. -#endif
  1115. -
  1116. -
  1117. -/****************************************************************************/
  1118. -/*                                                                          */
  1119. -/*                                 M A I N                                  */
  1120. -/*                                                                          */
  1121. -/****************************************************************************/
  1122. -
  1123. -void main(argc, argv)
  1124. -int argc;
  1125. -char ** argv;
  1126. -{
  1127. -
  1128. -    progname = *argv;
  1129. -    Argc = argc;
  1130. -    Argv = argv;
  1131. -
  1132. -    getargs();                              /* read command line arguments   */
  1133. -#if defined(MSDOS)
  1134. -    if ((DVIfile = fopen(DVIfilename, "rb")) == NULL)
  1135. -#else
  1136. -    if ((DVIfile = fopen(DVIfilename, "r")) == NULL)
  1137. -#endif
  1138. -        errorexit(filop);                   /* can't open dvifile            */
  1139. -
  1140. -    if (outputtofile) {                     /* open the outfile, if needed   */
  1141. -        if ((output = fopen(OUTfilename, "w")) == NULL)
  1142. -            errorexit(filcr);
  1143. -#if !defined(MSDOS)
  1144. -        pager = FALSE;
  1145. -#endif
  1146. -    }
  1147. -    else {
  1148. -        output = stdout;
  1149. -#if !defined(MSDOS)
  1150. -        if (isatty(fileno(output)) && pager) {   /* try to pipe to a pager   */
  1151. -            if ((output = popen(path, "w")) == NULL) /* get pipe to pager    */
  1152. -                errorexit(pipcr);                /* make output to output    */
  1153. -        }
  1154. -        else
  1155. -            pager = FALSE;
  1156. -#endif
  1157. -    }
  1158. -
  1159. -    dvimain();
  1160. -
  1161. -#if !defined(MSDOS)
  1162. -    if (pager)
  1163. -        pclose(output);                     /* close pipe to pager            */
  1164. -#endif
  1165. -
  1166. -    exit(0);
  1167. -
  1168. -} /* main */
  1169. -
  1170. -/*----------------------------------------------------------------------------*/
  1171. -
  1172. -void setoption(optarg)
  1173. -char *optarg;
  1174. -{
  1175. -    int j = 0;
  1176. -    int ret;
  1177. -   
  1178. -    while (strchr(OPTSET, optch) != NULL) {
  1179. -        switch (optch) {
  1180. -#if !defined(MSDOS)
  1181. -        case 'q' : pager = FALSE; break;
  1182. -        case 'f' : pager = TRUE; break;
  1183. -#endif
  1184. -        case 'l' : noffd = TRUE; break;
  1185. -        case 's' : scascii = TRUE; break;
  1186. -        case 'u' : scascii = FALSE; break;
  1187. -            case 'P' :
  1188. -               sequenceon = TRUE;     /* fall through */
  1189. -            case 'p' :
  1190. -                       if (pageswitchon)
  1191. -                           usage(onepp);
  1192. -                       getpages(j, optarg);
  1193. -                       break;
  1194. -            case 'w' :
  1195. -               if (getinteger(&ttywidth, &j, optarg))
  1196. -                           usage(nan);
  1197. -                       if (optarg[j] != '\0') 
  1198. -                           usage(gae);
  1199. -                       if ((ttywidth < 16) || (ttywidth > 132))
  1200. -                           usage(wrnge);
  1201. -                       break;
  1202. -            case 'e' :
  1203. -               if (getinteger(&espace, &j, optarg))
  1204. -                           usage(nan);
  1205. -                       if (optarg[j] != '\0') 
  1206. -                           usage(gae);
  1207. -                       break;
  1208. -            case 'o' :
  1209. -                       OUTfilename = optarg;
  1210. -               outputtofile = TRUE;
  1211. -                       j = strlen(optarg);
  1212. -                       break;
  1213. -#if !defined(MSDOS)
  1214. -            case 'F' :
  1215. -                       pager = TRUE;
  1216. -                       path = optarg;
  1217. -                       j = strlen(optarg);
  1218. -                       break;
  1219. -#endif
  1220. -            default  : 
  1221. -                       usage(bdopt);
  1222. -        }
  1223. -        if ((optch = optarg[j]) == '\0')
  1224. -            break;
  1225. -        j++;
  1226. -        if ((strchr(OPTWARG, optch) != NULL) && (optarg[j]='\0')) {
  1227. -                if (--Argc <= 0)
  1228. -                    usage(noarg);
  1229. -                optarg = *++Argv;
  1230. -                j = 0;
  1231. -            }
  1232. -    }
  1233. -} /* setoption */
  1234. -
  1235. -/*----------------------------------------------------------------------------*/
  1236. -
  1237. -void getargs()
  1238. -{
  1239. -    char *str, *envp;
  1240. -    bool DVIfound;                      /* if a dvi filename found           */
  1241. -
  1242. -    if (Argc <= 1)
  1243. -        usage(ign);
  1244. -
  1245. -    pageswitchon = FALSE;       /* show all pages                            */
  1246. -    sequenceon   = FALSE;       /* selected pages are TeX-numbered           */
  1247. -    outputtofile = FALSE;       /* write to stdout                           */
  1248. -#if !defined(MSDOS)
  1249. -    pager        = WANTPAGER;   /* want paging, compile time option          */
  1250. -#endif
  1251. -    noffd        = FALSE;       /* print formfeed between pages              */
  1252. -    scascii      = DEFSCAND;    /* scandinavian, compile time option         */
  1253. -    ttywidth     = 80;          /* default terminal width                    */
  1254. -    espace       = 0;           /* to fake ttywith calcs                     */
  1255. -    DVIfound     = FALSE;
  1256. -
  1257. -#if !defined(MSDOS)
  1258. -    if ((path = getenv("PAGER")) == NULL)   /* find default pathname of page */
  1259. -            path = DEFPAGER;             /* program in case paging is wanted */
  1260. -#endif
  1261. -
  1262. -    if ((envp = getenv("DVI2TTY")) != NULL) {
  1263. -        while (*envp == ' ')
  1264. -             envp++;
  1265. -        while (*envp) {                     /* environment var args          */
  1266. -            if (strchr(OPTSET, optch = *envp++) != NULL) {
  1267. -                /*
  1268. -                 * we always pass one option, and arrange for optarg ourselfves,
  1269. -                 * so setoption does not mesh up Argv
  1270. -                 */
  1271. -                if (strchr(OPTWARG, optch) != NULL) {
  1272. -                    while (*envp == ' ') 
  1273. -                        envp++;
  1274. -                    if (*envp == '\0')
  1275. -                        usage(noarg);
  1276. -                    str = envp;             /* str points to optarg          */
  1277. -                    while ((*envp != ' ') && (*envp != '\0'))
  1278. -                        *envp++;            /* set envp just after optarg    */
  1279. -                    if (*envp != '\0')
  1280. -                        *envp++ = '\0';     /* end optarg string             */
  1281. -                }
  1282. -                else
  1283. -                    str = "";
  1284. -                setoption(str);
  1285. -            }
  1286. -            else
  1287. -                usage(bdopt);
  1288. -            while (*envp == ' ')
  1289. -                 envp++;
  1290. -        }
  1291. -    }
  1292. -
  1293. -    while (--Argc > 0) {                    /* command line args             */
  1294. -        str = *++Argv;
  1295. -        if (*str != '-') {                  /* argument is not an option     */
  1296. -            if (DVIfound)                   /* only one dvi file allowed     */
  1297. -                usage(onef);
  1298. -            getname(str);
  1299. -            DVIfound = TRUE;
  1300. -        }
  1301. -        else if (strchr(OPTSET, optch = *++str) != NULL) {
  1302. -            str++;                      /* point to rest of argument if any  */
  1303. -            if ((strchr(OPTWARG, optch) != NULL) && (*str == '\0')) {
  1304. -                if (--Argc <= 0)
  1305. -                    usage(noarg);
  1306. -                str = *++Argv;
  1307. -            }
  1308. -            setoption(str);
  1309. -        }
  1310. -        else
  1311. -            usage(bdopt);
  1312. -    }
  1313. -
  1314. -    if (!DVIfound)
  1315. -        usage(ign);
  1316. -
  1317. -} /* getargs */
  1318. -
  1319. -/*---------------------------------------------------------------------------*/
  1320. -
  1321. -void getpages(j, str)
  1322. -int j;
  1323. -char *str;
  1324. -{
  1325. -    int i, c;
  1326. -    int num;
  1327. -
  1328. -    pageswitchon = TRUE;
  1329. -    firstpage = (printlisttype *) malloc(sizeof(printlisttype));
  1330. -    firstpage->all = FALSE;
  1331. -    firstpage->nxt = nil;
  1332. -    firstpage->pag = 0;
  1333. -    lastpage = firstpage;
  1334. -    currentpage = firstpage;
  1335. -    if (getinteger(&num, &j, str))
  1336. -        usage(nan);
  1337. -    plcnxt((int) num);
  1338. -    while (str[j]) {
  1339. -        c = str[j];
  1340. -        if (c == ',' || c == ':') {
  1341. -            j++;
  1342. -            if (getinteger(&num, &j, str))
  1343. -                usage(nan);
  1344. -        }
  1345. -        else
  1346. -            break;
  1347. -        if (c == ',')
  1348. -            plcnxt(num);
  1349. -        else {
  1350. -            if (currentpage->pag < 0) {
  1351. -                if (num > 0) {
  1352. -                    currentpage->all = TRUE;
  1353. -                    plcnxt(num);
  1354. -                }
  1355. -                else if (num < currentpage->pag)
  1356. -                    for (i = currentpage->pag - 1; i >= num; i--)
  1357. -                        plcnxt(i);
  1358. -                else
  1359. -                    usage(bdlst);
  1360. -            }
  1361. -            else {
  1362. -                if (num < currentpage->pag)
  1363. -                    usage(bdlst);
  1364. -                for (i = currentpage->pag + 1; i <= num; i++)
  1365. -                    plcnxt(i);
  1366. -            }
  1367. -        }
  1368. -    }
  1369. -    if ((str[j] != ' ') && (str[j] != NULL)) {
  1370. -        usage(gae);
  1371. -    }
  1372. -    currentpage = firstpage;
  1373. -
  1374. -} /* getpages */
  1375. -
  1376. -
  1377. -void plcnxt(pagnr)      /* place page-nr next in list */
  1378. -int pagnr;
  1379. -{
  1380. -    currentpage = lastpage;
  1381. -    currentpage->pag = pagnr;
  1382. -    lastpage = (printlisttype *) malloc(sizeof(printlisttype));
  1383. -    lastpage->all = FALSE;
  1384. -    lastpage->nxt = nil;
  1385. -    lastpage->pag = 0;
  1386. -    currentpage->nxt = lastpage;
  1387. -
  1388. -} /* plcnxt */
  1389. -
  1390. -/*----------------------------------------------------------------------------*/
  1391. -
  1392. -void getname(str)
  1393. -char *str;
  1394. -{
  1395. -    int   i;
  1396. -
  1397. -    i = strlen(str);
  1398. -    if (i == 0)
  1399. -        usage(ign);
  1400. -    strcpy(DVIfilename, str);
  1401. -    if (!((i >= 5) && (str[i-1] == 'i') && (str[i-2] == 'v') &&
  1402. -          (str[i-3] = 'd') && (str[i-4] = '.'))) {
  1403. -        strcat(DVIfilename, ".dvi");
  1404. -    }
  1405. -
  1406. -} /* getname */
  1407. -
  1408. -/*----------------------------------------------------------------------------*/
  1409. -
  1410. -int getinteger(dest, j, str)
  1411. -int *dest;
  1412. -int *j;
  1413. -char *str;
  1414. -{
  1415. -    int  cum;
  1416. -    int  sgn;
  1417. -    char ch;
  1418. -
  1419. -    ch = str[*j];
  1420. -    if (ch == '-') {
  1421. -        sgn = -1;
  1422. -        ch  = str[++(*j)];
  1423. -    }
  1424. -    else
  1425. -        sgn = 1;
  1426. -    if ((ch >= '0') && (ch <= '9')) {
  1427. -        cum = 0;
  1428. -        while ((ch >= '0') && (ch <= '9')) {
  1429. -            cum = cum*10 + ch - '0';
  1430. -            ch = str[++(*j)];
  1431. -        }
  1432. -        *dest = sgn * cum;
  1433. -        return 0;                   /* return ok */
  1434. -    }
  1435. -    return 1;                       /* return error */
  1436. -
  1437. -}   /* getinteger */
  1438. -
  1439. -/*----------------------------------------------------------------------------*/
  1440. -
  1441. -void errorexit(errorcode)
  1442. -int errorcode;
  1443. -{
  1444. -
  1445. -    fprintf(stderr, "%s: ", progname);
  1446. -    switch (errorcode) {
  1447. -        case  illop : fprintf(stderr, "Illegal op-code found: %d\n", opcode);
  1448. -                      break;
  1449. -        case  stkof : fprintf(stderr, "Stack overflow\n");
  1450. -                      break;
  1451. -        case  stkuf : fprintf(stderr, "Stack underflow\n");
  1452. -                      break;
  1453. -        case  stkrq : fprintf(stderr, "Cannot create dvi stack\n");
  1454. -                      break;
  1455. -        case  lnerq : fprintf(stderr, "Cannot allocate memory\n");
  1456. -                      break;
  1457. -        case  badid : fprintf(stderr, "Id-byte is not correct: %d\n ", opcode);
  1458. -                      break;
  1459. -        case  bdsgn : fprintf(stderr, "Bad signature: %d (not 223)\n",
  1460. -                                      (int) foo);
  1461. -                      break;
  1462. -        case  fwsgn : fprintf(stderr, "%d signature bytes (min. 4)\n",
  1463. -                                      (int) foo);
  1464. -                      break;
  1465. -        case  nopre : fprintf(stderr, "Missing preamble\n");
  1466. -                      break;
  1467. -        case  nobop : fprintf(stderr, "Missing beginning-of-page command\n");
  1468. -                      break;
  1469. -        case  nopp  : fprintf(stderr, "Missing post-post command\n");
  1470. -                      break;
  1471. -        case  bdpre : fprintf(stderr, "Preamble occured inside a page\n");
  1472. -                      break;
  1473. -        case  bdbop : fprintf(stderr, "BOP-command occured inside a page\n");
  1474. -                      break;
  1475. -        case  bdpst : fprintf(stderr, "Postamble occured before end-of-page\n");
  1476. -                      break;
  1477. -        case  bdpp  : fprintf(stderr, "Postpost occured before post-command\n");
  1478. -                      break;
  1479. -        case  nopst : fprintf(stderr, "Missing postamble\n");
  1480. -                      break;
  1481. -        case  illch : fprintf(stderr, "Character code out of range, 0..127\n");
  1482. -                      break;
  1483. -        case  filop : fprintf(stderr, "Cannot open dvifile\n");
  1484. -                      break;
  1485. -        case  filcr : fprintf(stderr, "Cannot create outfile\n");
  1486. -                      break;
  1487. -#if !defined(MSDOS)
  1488. -        case  pipcr : fprintf(stderr, "Cannot create pipe to pager\n");
  1489. -                      break;
  1490. -#endif
  1491. -        default     : fprintf(stderr, "Unkown error code\n");
  1492. -                      break;
  1493. -    };
  1494. -    if (outputtofile)
  1495. -        unlink(OUTfilename);
  1496. -    exit(errorcode);
  1497. -
  1498. -}  /* errorexit */
  1499. -
  1500. -/*----------------------------------------------------------------------------*/
  1501. -
  1502. -void usage(uerr)
  1503. -int uerr;
  1504. -{
  1505. -
  1506. -    if (uerr != ign) {
  1507. -        fprintf(stderr,"%s: ", progname);
  1508. -        switch (uerr) {
  1509. -            case   ign    : fprintf(stderr, "%s", Copyright);
  1510. -                            break;
  1511. -            case   wrnge  : fprintf(stderr, "width arg out of range:16-132");
  1512. -                            break;
  1513. -            case   nan    : fprintf(stderr, "numeric argument expected for option %c",
  1514. -                                            optch);
  1515. -                            break;
  1516. -            case   gae    : fprintf(stderr, "garbage in argument for option %c",
  1517. -                                            optch);
  1518. -                            break;
  1519. -            case   bdlst  : fprintf(stderr, "mal-formed list of pagenumbers");
  1520. -                            break;
  1521. -            case   onef   : fprintf(stderr, "only one infile argument allowed");
  1522. -                            break;
  1523. -            case   noarg  : fprintf(stderr, "option argument expected for option %c",
  1524. -                                            optch);
  1525. -                            break;
  1526. -            case   bdopt  : fprintf(stderr, "bad option %c", optch);
  1527. -                            break;
  1528. -            case   onepp  : fprintf(stderr, "only one pagelist allowed");
  1529. -                            break;
  1530. -            default       : fprintf(stderr, "unknown usage error");
  1531. -                            break;
  1532. -        }
  1533. -        fprintf(stderr, "\n");
  1534. -    }
  1535. -    fprintf(stderr, "Usage: %s [ options ] dvifile[.dvi]\n", progname);
  1536. -    fprintf(stderr, "Options are:\n");
  1537. -    fprintf(stderr,
  1538. -            " -ofile   Write output to file, else write to stdout.\n");
  1539. -    fprintf(stderr,
  1540. -            " -plist   Print pages whos TeX-page-number are in list.\n");
  1541. -    fprintf(stderr,
  1542. -            " -Plist   Print pages whos sequential number are in list.\n");
  1543. -    fprintf(stderr,
  1544. -            " -wn      Print the lines with width n characters, default 80.\n");
  1545. -#if !defined(MSDOS)
  1546. -    fprintf(stderr, " -f       Try to pipe to a pager if output is a tty");
  1547. -    if (WANTPAGER)
  1548. -        fprintf(stderr, " (default).\n");
  1549. -    else
  1550. -        fprintf(stderr, ".\n");
  1551. -    fprintf(stderr, " -q       Don't try to pipe to a pager");
  1552. -    if (WANTPAGER)
  1553. -        fprintf(stderr, ".\n");
  1554. -    else
  1555. -        fprintf(stderr, " (default).\n");
  1556. -    fprintf(stderr, " -Fprog   Pipe output to pager prog.\n");
  1557. -#endif
  1558. -    fprintf(stderr,
  1559. -            " -l       Write ''^L'' instead of formfeed between pages.\n");
  1560. -    fprintf(stderr,
  1561. -            " -u       National Swedish characters printed as aaoAAO");
  1562. -    if (DEFSCAND)
  1563. -        fprintf(stderr, ".\n");
  1564. -    else
  1565. -        fprintf(stderr, " (default).\n");
  1566. -    fprintf(stderr,
  1567. -            " -s       National Swedish characters printed as }{|][\\");
  1568. -    if (DEFSCAND)
  1569. -        fprintf(stderr, " (default).\n");
  1570. -    else
  1571. -        fprintf(stderr, ".\n");
  1572. -    exit(uerr);
  1573. -
  1574. -} /* usage */
  1575. -
  1576. _E_O_F_
  1577. if test 23102 -ne `wc -c < dvi2tty.c `; then
  1578.     echo shar: "'dvi2tty.c'" unpacked with wrong size!
  1579. fi
  1580. echo shar: extracting dvistuff.c
  1581. if test -f 'dvistuff.c'
  1582. then
  1583.     echo shar: over-writing existing file "'dvistuff.c'"
  1584. fi
  1585. sed -e 's/^-//' << \_E_O_F_ > dvistuff.c
  1586. -
  1587. -
  1588. -#include "dvi2tty.h"
  1589. -#include <sys/types.h>
  1590. -#include <sys/stat.h>
  1591. -#if defined(MSDOS)
  1592. -#include <math.h>
  1593. -#endif
  1594. -#include "commands.h"
  1595. -
  1596. -#define VERSIONID            2 /* dvi version number that pgm handles      */
  1597. -#define VERTICALEPSILON 450000L /* crlf when increasing v more than this   */
  1598. -
  1599. -#define rightmargin     152    /* nr of columns allowed to the right of h=0*/
  1600. -#define leftmargin      -50    /* give some room for negative h-coordinate */
  1601. -#define LINELEN         203    /* rightmargin - leftmargin + 1 */
  1602. -
  1603. -#define MOVE            TRUE   /* if advancing h when outputing a rule     */
  1604. -#define STAY            FALSE  /* if not advancing h when outputing a rule */
  1605. -
  1606. -#define absolute        0      /* for seeking in files                     */
  1607. -#define relative        1
  1608. -
  1609. -#define FORM             12    /* formfeed                                 */
  1610. -#define SPACE            32    /* space                                    */
  1611. -#define DEL             127    /* delete                                   */
  1612. -
  1613. -#define LASTCHAR        127    /* max dvi character, above are commands    */
  1614. -
  1615. -#define IMIN(a, b)      (a<b ? a : b)
  1616. -#define IMAX(a, b)      (a>b ? a : b)
  1617. -
  1618. -#define get1()          num(1)
  1619. -#define get2()          num(2)
  1620. -#define get3()          num(3)
  1621. -#define get4()          num(4)
  1622. -#define sget1()         snum(1)
  1623. -#define sget2()         snum(2)
  1624. -#define sget3()         snum(3)
  1625. -#define sget4()         snum(4)
  1626. -
  1627. -char *dvistuff = "(#)@  dvistuff.c  3.1 23/01/89 M.J.E. Mol (c) 1989"
  1628. -
  1629. -/*---------------------------------------------------------------------------*/
  1630. -
  1631. -typedef struct {
  1632. -    long hh;
  1633. -    long vv;
  1634. -    long ww;
  1635. -    long xx;
  1636. -    long yy;
  1637. -    long zz;
  1638. -} stackitem;
  1639. -
  1640. -typedef struct lineptr {        /* the lines of text to be output to outfile */
  1641. -    long            vv;                 /* vertical position of the line     */
  1642. -    int             charactercount;     /* pos of last char on line          */
  1643. -    struct lineptr *prev;               /* preceding line                    */
  1644. -    struct lineptr *next;               /* succeeding line                   */
  1645. -    char            text[LINELEN+1];    /* leftmargin...rightmargin          */
  1646. -} linetype;
  1647. -
  1648. -/*---------------------------------------------------------------------------*/
  1649. -
  1650. -bool        pageswitchon;       /* true if user-set pages to print           */
  1651. -bool        sequenceon;         /* false if pagesw-nrs refers to TeX-nrs     */
  1652. -bool        scascii;            /* if true make Scand. nat. chars right      */
  1653. -bool        noffd;              /* if true output ^L instead of formfeed     */
  1654. -
  1655. -int         opcode;             /* dvi-opcodes                               */
  1656. -
  1657. -long        h, v;               /* coordinates, horizontal and vertical      */
  1658. -long        w, x, y, z;         /* horizontal and vertical amounts           */
  1659. -
  1660. -long        pagecounter;        /* sequence page number counter              */
  1661. -long        backpointer;        /* pointer for offset to previous page       */
  1662. -long        pagenr;             /* TeX page number                           */
  1663. -int         stackmax;           /* stacksize required                        */
  1664. -
  1665. -long        maxpagewidth;       /* width of widest page in file              */
  1666. -long        charwidth;          /* aprox width of character                  */
  1667. -
  1668. -linetype *  currentline;        /* pointer to current line on current page   */
  1669. -linetype *  firstline;          /* pointer to first line on current page     */
  1670. -linetype *  lastline;           /* pointer to last line on current page      */
  1671. -int         firstcolumn;        /* 1st column with something to print        */
  1672. -
  1673. -stackitem * stack;              /* stack for dvi-pushes                      */
  1674. -int         sptr;               /* stack pointer                             */
  1675. -
  1676. -/*---------------------------------------------------------------------------*/
  1677. -
  1678. -#if defined(MSDOS)
  1679. -void            postamble       (void);
  1680. -void            preamble        (void);
  1681. -void            walkpages       (void);
  1682. -void            initpage        (void);
  1683. -void            dopage          (void);
  1684. -void            skippage        (void);
  1685. -void            printpage       (void);
  1686. -bool            inlist          (long);
  1687. -void            rule            (bool, long, long);
  1688. -void            ruleaux         (long, long, char);
  1689. -long            horizontalmove  (long);
  1690. -int             skipnops        (void);
  1691. -linetype    *   getline         (void);
  1692. -linetype    *   findline        (void);
  1693. -unsigned long   num             (int);
  1694. -long            snum            (int);
  1695. -void            outchar         (char);
  1696. -void            putcharacter    (long);
  1697. -void            setchar         (long);
  1698. -#else
  1699. -void            postamble       ();
  1700. -void            preamble        ();
  1701. -void            walkpages       ();
  1702. -void            initpage        ();
  1703. -void            dopage          ();
  1704. -void            skippage        ();
  1705. -void            printpage       ();
  1706. -bool            inlist          ();
  1707. -void            rule            ();
  1708. -void            ruleaux         ();
  1709. -long            horizontalmove  ();
  1710. -int             skipnops        ();
  1711. -linetype    *   getline         ();
  1712. -linetype    *   findline        ();
  1713. -unsigned long   num             ();
  1714. -long            snum            ();
  1715. -void            outchar         ();
  1716. -void            putcharacter    ();
  1717. -void            setchar         ();
  1718. -#endif
  1719. -
  1720. -
  1721. -/*---------------------------------------------------------------------------*/
  1722. -/*---------------------------------------------------------------------------*/
  1723. -
  1724. -/*
  1725. - * The main function for processing the dvi file.
  1726. - * Here we assume there are to file pointers: DVIfile and output.
  1727. - * Also we have a list of pages pointed to by 'currentpage',
  1728. - * which is only used (in 'inlist()') when a page list is given.
  1729. - */
  1730. -
  1731. -void dvimain()
  1732. -{
  1733. -
  1734. -    postamble();                            /* seek and process the postamble */
  1735. -    /* note that walkpages *must* immediately follow preamble */
  1736. -    preamble();                             /* process preamble               */
  1737. -    walkpages();                            /* time to do the actual work!    */
  1738. -
  1739. -} /* dvimain */
  1740. -
  1741. -/*---------------------------------------------------------------------------*/
  1742. -
  1743. -void postamble()            /* find and process postamble, use random access */
  1744. -{
  1745. -    register long size;
  1746. -    register int  count;
  1747. -    struct stat st;
  1748. -
  1749. -    fstat (fileno(DVIfile), &st);
  1750. -    size = (long) st.st_size;                   /* get size of file          */
  1751. -    count = -1;
  1752. -    do {              /* back file up past signature bytes (223), to id-byte */
  1753. -        if (size == 0)
  1754. -            errorexit(nopst);
  1755. -        size--;
  1756. -        fseek(DVIfile, size, absolute);
  1757. -        opcode = (int) get1();
  1758. -        count++;
  1759. -    } while (opcode == TRAILER);
  1760. -    if (count < 4) {                            /* must have 4 trailer bytes */
  1761. -         foo = count;
  1762. -         errorexit(fwsgn);
  1763. -    }
  1764. -    if (opcode != VERSIONID)
  1765. -        errorexit(badid);
  1766. -    fseek(DVIfile, size-4, absolute);       /* back up to back-pointer       */
  1767. -    fseek(DVIfile, sget4(), absolute);      /* and to start of postamble   */
  1768. -    if (get1() != POST)
  1769. -        errorexit(nopst);
  1770. -    fseek(DVIfile, 20L, relative); /* lastpageoffset, numerator, denominator */
  1771. -                                   /* magnification, maxpageheight           */
  1772. -    maxpagewidth = sget4();
  1773. -    charwidth = maxpagewidth / (ttywidth + espace); 
  1774. -    stackmax = (int) get2();
  1775. -    if ((stack = (stackitem *) malloc(stackmax * sizeof(stackitem))) == NULL)
  1776. -       errorexit(stkrq);
  1777. -
  1778. -    /* get2() -- totalpages */
  1779. -    /* fontdefs */
  1780. -
  1781. -} /* postamble */
  1782. -
  1783. -/*---------------------------------------------------------------------------*/
  1784. -
  1785. -void preamble()                 /* process preamble, use random access       */
  1786. -{
  1787. -
  1788. -    fseek(DVIfile, 0L, absolute);       /* read the dvifile from the start   */
  1789. -    if ((opcode = skipnops()) != PRE)
  1790. -        errorexit(nopre);
  1791. -    opcode = (int) get1();        /* check id in preamble, ignore rest of it */
  1792. -    if (opcode != VERSIONID)
  1793. -        errorexit(badid);
  1794. -    fseek(DVIfile, 12L, relative);  /* numerator, denominator, magnification */
  1795. -    fseek(DVIfile, get1(), relative);         /* skip job identification     */
  1796. -
  1797. -} /* preamble */
  1798. -
  1799. -/*----------------------------------------------------------------------------*/
  1800. -
  1801. -void walkpages()                  /* process the pages in the DVI-file */
  1802. -{
  1803. -    register bool wantpage;
  1804. -
  1805. -    pagecounter = 0L;
  1806. -    while ((opcode = skipnops()) != POST) {
  1807. -        if (opcode != BOP)              /* should be at start of page now    */
  1808. -            errorexit(nobop);
  1809. -        else {
  1810. -            pagecounter++;
  1811. -            pagenr = sget4();           /* get TeX page number               */
  1812. -            fseek(DVIfile, 36L, relative); /* skip page header */
  1813. -            backpointer = sget4();      /* get previous page offset          */
  1814. -            if (pageswitchon)
  1815. -                if (sequenceon)
  1816. -                    wantpage = inlist(pagecounter);
  1817. -                else
  1818. -                    wantpage = inlist(pagenr);
  1819. -            else
  1820. -                wantpage = TRUE;
  1821. -
  1822. -            if (wantpage) {
  1823. -                initpage();
  1824. -                dopage();
  1825. -                printpage();
  1826. -            }
  1827. -            else {
  1828. -                skippage();
  1829. -            }
  1830. -        }
  1831. -    }
  1832. -
  1833. -} /* walkpages */
  1834. -
  1835. -/*---------------------------------------------------------------------------*/
  1836. -
  1837. -void initpage()
  1838. -{
  1839. -
  1840. -    h = 0L;  v = 0L;                        /* initialize coordinates   */
  1841. -    x = 0L;  w = 0L;  y = 0L;  z = 0L;      /* initialize amounts       */
  1842. -    sptr = 0;                               /* initialize stack         */
  1843. -    currentline = getline();                /* initialize list of lines */
  1844. -    currentline->vv = 0L;
  1845. -    firstline   = currentline;
  1846. -    lastline    = currentline;
  1847. -    firstcolumn = rightmargin;
  1848. -    if (pageswitchon) {
  1849. -        if ((sequenceon && (pagecounter != firstpage->pag)) ||
  1850. -            (!sequenceon && (pagenr != firstpage->pag)))
  1851. -            if (noffd)
  1852. -                fprintf(output, "^L\n");
  1853. -            else
  1854. -                putc(FORM, output);
  1855. -    }
  1856. -    else
  1857. -        if (backpointer != -1)              /* not FORM at first page   */
  1858. -            if (noffd)
  1859. -                fprintf(output, "^L\n");
  1860. -            else
  1861. -                putc(FORM, output);
  1862. -
  1863. -} /* initpage */
  1864. -
  1865. -/*----------------------------------------------------------------------------*/
  1866. -
  1867. -void dopage()
  1868. -{
  1869. -
  1870. -    while ((opcode = (int) get1()) != EOP) {    /* process page until eop */
  1871. -        if (opcode > POST_POST)
  1872. -            errorexit(illop);
  1873. -        else if (opcode <= LASTCHAR)
  1874. -            outchar((char) opcode);
  1875. -        else
  1876. -            switch (opcode) {
  1877. -                case SET1     : setchar(get1()); break;
  1878. -                case SET2     : setchar(get2()); break;
  1879. -                case SET3     : setchar(get3()); break;
  1880. -                case SET4     : setchar(get4()); break;
  1881. -                case SET_RULE : rule(MOVE, sget4(), sget4()); break;
  1882. -                case PUT1     : putcharacter(get1()); break;
  1883. -                case PUT2     : putcharacter(get2()); break;
  1884. -                case PUT3     : putcharacter(get3()); break;
  1885. -                case PUT4     : putcharacter(get4()); break;
  1886. -                case PUT_RULE : rule(STAY, sget4(), sget4()); break;
  1887. -                case NOP      : break;  /* no-op */
  1888. -                case BOP      : errorexit(bdbop); break;
  1889. -/*              case EOP      : break;  strange place to have EOP */
  1890. -                case PUSH     : if (sptr >= stackmax)            /* push */
  1891. -                                     errorexit(stkof);
  1892. -                                stack[sptr].hh = h;
  1893. -                                stack[sptr].vv = v;
  1894. -                                stack[sptr].ww = w;
  1895. -                                stack[sptr].xx = x;
  1896. -                                stack[sptr].yy = y;
  1897. -                                stack[sptr].zz = z;
  1898. -                                sptr++;
  1899. -                                break;
  1900. -                case POP      : if (sptr == 0)                   /* pop */
  1901. -                                    errorexit(stkuf);
  1902. -                                sptr--;
  1903. -                                h = stack[sptr].hh;
  1904. -                                v = stack[sptr].vv;
  1905. -                                w = stack[sptr].ww;
  1906. -                                x = stack[sptr].xx;
  1907. -                                y = stack[sptr].yy;
  1908. -                                z = stack[sptr].zz;
  1909. -                                break;
  1910. -                case RIGHT1   : (void) horizontalmove(sget1()); break;
  1911. -                case RIGHT2   : (void) horizontalmove(sget2()); break;
  1912. -                case RIGHT3   : (void) horizontalmove(sget3()); break;
  1913. -                case RIGHT4   : (void) horizontalmove(sget4()); break;
  1914. -                case W0       : h += w; break;
  1915. -                case W1       : w = horizontalmove(sget1()); break;
  1916. -                case W2       : w = horizontalmove(sget2()); break;
  1917. -                case W3       : w = horizontalmove(sget3()); break;
  1918. -                case W4       : w = horizontalmove(sget4()); break;
  1919. -                case X0       : h += x; break;
  1920. -                case X1       : x = horizontalmove(sget1()); break;
  1921. -                case X2       : x = horizontalmove(sget2()); break;
  1922. -                case X3       : x = horizontalmove(sget3()); break;
  1923. -                case X4       : x = horizontalmove(sget4()); break;
  1924. -                case DOWN1    : v += sget1(); break;
  1925. -                case DOWN2    : v += sget2(); break;
  1926. -                case DOWN3    : v += sget3(); break;
  1927. -                case DOWN4    : v += sget4(); break;
  1928. -                case Y0       : v += y; break;
  1929. -                case Y1       : y = sget1(); v += y; break;
  1930. -                case Y2       : y = sget2(); v += y; break;
  1931. -                case Y3       : y = sget3(); v += y; break;
  1932. -                case Y4       : y = sget4(); v += y; break;
  1933. -                case Z0       : v += z; break;
  1934. -                case Z1       : z = sget1(); v += z; break;
  1935. -                case Z2       : z = sget2(); v += z; break;
  1936. -                case Z3       : z = sget3(); v += z; break;
  1937. -                case Z4       : z = sget4(); v += z; break;
  1938. -                case FNT1     :
  1939. -                case FNT2     :
  1940. -                case FNT3     :                       /* ignore font changes */
  1941. -                case FNT4     : fseek(DVIfile, (long) opcode-FNT1+1, relative);
  1942. -                                break;
  1943. -                case XXX1     : fseek(DVIfile, get1(), relative); break;
  1944. -                case XXX2     : fseek(DVIfile, get2(), relative); break;
  1945. -                case XXX3     : fseek(DVIfile, get3(), relative); break;
  1946. -                case XXX4     : fseek(DVIfile, get4(), relative); break;
  1947. -                case FNT_DEF1 :
  1948. -                case FNT_DEF2 :
  1949. -                case FNT_DEF3 :                   /* ignore font definitions */
  1950. -                case FNT_DEF4 : fseek(DVIfile, (long) opcode-FNT_DEF1+1+12,
  1951. -                                               relative);
  1952. -                                fseek(DVIfile, get1() + get1(), relative);
  1953. -                                break;
  1954. -                case PRE      : errorexit(bdpre); break;
  1955. -                case POST     : errorexit(bdpst); break;
  1956. -                case POST_POST: errorexit(bdpp); break;
  1957. -            }
  1958. -    }
  1959. -
  1960. -} /* dopage */
  1961. -
  1962. -/*----------------------------------------------------------------------------*/
  1963. -
  1964. -void skippage()                /* skip past one page */
  1965. -{
  1966. -    register int opcode;
  1967. -
  1968. -    while ((opcode = (int) get1()) != EOP) {
  1969. -        if (opcode > POST_POST)
  1970. -            errorexit(illop);
  1971. -        else
  1972. -            switch (opcode) {
  1973. -                case SET1     :
  1974. -                case PUT1     :
  1975. -                case RIGHT1   :
  1976. -                case W1       :
  1977. -                case X1       :
  1978. -                case DOWN1    :
  1979. -                case Y1       :
  1980. -                case Z1       :
  1981. -                case FNT1     : fseek(DVIfile, 1L, relative); break;
  1982. -                case SET2     :
  1983. -                case PUT2     :
  1984. -                case RIGHT2   :
  1985. -                case W2       :
  1986. -                case X2       :
  1987. -                case DOWN2    :
  1988. -                case Y2       :
  1989. -                case Z2       :
  1990. -                case FNT2     : fseek(DVIfile, 2L, relative); break;
  1991. -                case SET3     :
  1992. -                case PUT3     :
  1993. -                case RIGHT3   :
  1994. -                case W3       :
  1995. -                case X3       :
  1996. -                case DOWN3    :
  1997. -                case Y3       :
  1998. -                case Z3       :
  1999. -                case FNT3     : fseek(DVIfile, 3L, relative); break;
  2000. -                case SET4     :
  2001. -                case PUT4     :
  2002. -                case RIGHT4   :
  2003. -                case W4       :
  2004. -                case X4       :
  2005. -                case DOWN4    :
  2006. -                case Y4       :
  2007. -                case Z4       :
  2008. -                case FNT4     : fseek(DVIfile, 4L, relative); break;
  2009. -                case SET_RULE :
  2010. -                case PUT_RULE : fseek(DVIfile, 8L, relative); break;
  2011. -                case BOP      : errorexit(bdbop); break;
  2012. -                case XXX1     : fseek(DVIfile, get1(), relative); break;
  2013. -                case XXX2     : fseek(DVIfile, get2(), relative); break;
  2014. -                case XXX3     : fseek(DVIfile, get3(), relative); break;
  2015. -                case XXX4     : fseek(DVIfile, get4(), relative); break;
  2016. -                case FNT_DEF1 :
  2017. -                case FNT_DEF2 :
  2018. -                case FNT_DEF3 :
  2019. -                case FNT_DEF4 : fseek(DVIfile, (long) opcode-FNT_DEF1+1+12,
  2020. -                                      relative);
  2021. -                                fseek(DVIfile, get1()+get1(), relative);
  2022. -                                break;
  2023. -                case PRE      : errorexit(bdpre); break;
  2024. -                case POST     : errorexit(bdpst); break;
  2025. -                case POST_POST: errorexit(bdpp); break;
  2026. -        }
  2027. -    }
  2028. -
  2029. -} /* skippage */
  2030. -
  2031. -/*---------------------------------------------------------------------------*/
  2032. -
  2033. -void printpage()       /* 'end of page', writes lines of page to output file */
  2034. -{
  2035. -    register int  i, j;
  2036. -    register char ch;
  2037. -
  2038. -    if (sptr != 0)
  2039. -        fprintf(stderr, "dvi2tty: warning - stack not empty at eop.\n");
  2040. -    for (currentline = firstline; currentline != nil;
  2041. -          currentline = currentline->next) {
  2042. -        if (currentline != firstline) {
  2043. -            foo = ((currentline->vv - currentline->prev->vv)/VERTICALEPSILON)-1;
  2044. -            if (foo > 3)
  2045. -                foo = 3;        /* linespacings not too large */
  2046. -            for (i = 1; i <= (int) foo; i++)
  2047. -                putc('\n', output);
  2048. -        }
  2049. -        if (currentline->charactercount >= leftmargin) {
  2050. -            foo = ttywidth - 2;
  2051. -            for (i = firstcolumn, j = 1; i <= currentline->charactercount;
  2052. -                   i++, j++) {
  2053. -                ch = currentline->text[i - leftmargin];
  2054. -                if (ch >= SPACE)
  2055. -                    putc(ch, output);
  2056. -                if ((j > (int) foo) && (currentline->charactercount > i+1)) {
  2057. -                        fprintf(output, "*\n");         /* if line to large */
  2058. -                        fprintf(output, " *");          /* mark output      */
  2059. -                        j = 2;
  2060. -                }
  2061. -            } 
  2062. -        }
  2063. -        putc('\n', output);
  2064. -    } 
  2065. -
  2066. -    currentline = firstline;
  2067. -    while (currentline->next != nil) {
  2068. -        currentline = currentline->next;
  2069. -        free(currentline->prev);
  2070. -    }
  2071. -    free(currentline);              /* free last line */
  2072. -    currentline = nil;
  2073. -
  2074. -} /* printpage */
  2075. -
  2076. -/*----------------------------------------------------------------------------*/
  2077. -
  2078. -bool inlist(pagenr)                         /* ret true if in list of pages */
  2079. -register long pagenr;
  2080. -{
  2081. -
  2082. -    while ((currentpage->pag < 0) && (currentpage->pag != pagenr) &&
  2083. -           !currentpage->all && (currentpage->nxt != nil))
  2084. -        currentpage = currentpage->nxt;
  2085. -    if ((currentpage->all && (pagenr < currentpage->pag)) ||
  2086. -         (currentpage->pag == pagenr))
  2087. -            return TRUE;
  2088. -    else if (pagenr > 0) {
  2089. -        while ((currentpage->pag < pagenr) && (currentpage->nxt != nil))
  2090. -            currentpage = currentpage->nxt;
  2091. -        if (currentpage->pag == pagenr)
  2092. -            return TRUE;
  2093. -    }
  2094. -    return FALSE;
  2095. -
  2096. -} /* inlist */
  2097. -
  2098. -/*----------------------------------------------------------------------------*/
  2099. -
  2100. -void rule(moving, rulewt, ruleht)
  2101. -register bool moving;
  2102. -register long rulewt, ruleht;
  2103. -{   /* output a rule (vertical or horizontal), increment h if moving is true */
  2104. -
  2105. -    register char ch;               /* character to set rule with            */
  2106. -    register long saveh, savev;
  2107. -                              /* rule   --   starts up the recursive routine */
  2108. -    if (!moving)
  2109. -        saveh = h;
  2110. -    if ((ruleht <= 0) || (rulewt <= 0))
  2111. -        h += rulewt;
  2112. -    else {
  2113. -        savev = v;
  2114. -        if ((ruleht / rulewt) > 0)
  2115. -            ch = '|';
  2116. -        else if (ruleht > (VERTICALEPSILON / 2))
  2117. -            ch = '=';
  2118. -        else
  2119. -            ch = '_';
  2120. -        ruleaux(rulewt, ruleht, ch);
  2121. -        v = savev;
  2122. -    }
  2123. -    if (!moving)
  2124. -        h = saveh;
  2125. -
  2126. -} /* rule */
  2127. -
  2128. -
  2129. -
  2130. -void ruleaux(rulewt, ruleht, ch)     /* recursive  that does the job */
  2131. -register long rulewt, ruleht;
  2132. -register char ch;
  2133. -{
  2134. -    register long wt, lmh, rmh;
  2135. -
  2136. -    wt = rulewt;
  2137. -    lmh = h;                        /* save left margin                      */
  2138. -    if (h < 0) {                    /* let rules that start at negative h    */
  2139. -        wt -= h;                    /* start at coordinate 0, but let it     */
  2140. -        h = 0;                      /*   have the right length               */
  2141. -    }
  2142. -    while (wt > 0) {                /* output the part of the rule that      */
  2143. -        rmh = h;                    /*   goes on this line                   */
  2144. -        outchar(ch);
  2145. -        wt -= (h-rmh);              /* decrease the width left on line       */
  2146. -    }
  2147. -    ruleht -= VERTICALEPSILON;      /* decrease the height                   */
  2148. -    if (ruleht > VERTICALEPSILON) { /* still more vertical?                  */
  2149. -        rmh = h;                    /* save current h (right margin)         */
  2150. -        h = lmh;                    /* restore left margin                   */
  2151. -        v -= (VERTICALEPSILON + VERTICALEPSILON / 10);
  2152. -        ruleaux(rulewt, ruleht, ch);
  2153. -        h = rmh;                    /* restore right margin                  */
  2154. -    }
  2155. -
  2156. -} /* ruleaux */
  2157. -
  2158. -/*----------------------------------------------------------------------------*/
  2159. -
  2160. -long horizontalmove(amount)
  2161. -register long amount;
  2162. -{
  2163. -
  2164. -#if defined(MSDOS)
  2165. -    if (labs(amount) > charwidth / 4L) {
  2166. -#else
  2167. -    if (abs(amount) > charwidth / 4L) {
  2168. -#endif
  2169. -        foo = 3*charwidth / 4;
  2170. -        if (amount > 0)
  2171. -            amount = ((amount+foo) / charwidth) * charwidth;
  2172. -        else
  2173. -            amount = ((amount-foo) / charwidth) * charwidth;
  2174. -        h += amount;
  2175. -        return amount;
  2176. -    }
  2177. -    else
  2178. -        return 0;
  2179. -
  2180. -}   /* horizontalmove */
  2181. -
  2182. -/*----------------------------------------------------------------------------*/
  2183. -
  2184. -int skipnops()                      /* skips by no-op commands  */
  2185. -{
  2186. -    register int opcode;
  2187. -
  2188. -    while ((opcode = (int) num(1)) == NOP);
  2189. -    return opcode;
  2190. -
  2191. -} /* skipnops */
  2192. -
  2193. -/*----------------------------------------------------------------------------*/
  2194. -
  2195. -linetype *getline()             /* returns an initialized line-object */
  2196. -{
  2197. -    register int  i;
  2198. -    register linetype *temp;
  2199. -
  2200. -    if ((temp = (linetype *) malloc(sizeof(linetype))) == NULL) 
  2201. -        errorexit(lnerq);
  2202. -    temp->charactercount = leftmargin - 1;
  2203. -    temp->prev = nil;
  2204. -    temp->next = nil;
  2205. -    for (i = 0; i < LINELEN; i++)
  2206. -        temp->text[i] = ' ';
  2207. -    temp->text[i] = '\0';
  2208. -    return temp;
  2209. -
  2210. -} /* getline */
  2211. -
  2212. -/*----------------------------------------------------------------------------*/
  2213. -
  2214. -linetype *findline()            /* find best fit line were text should go */
  2215. -{                               /* and generate new line if needed        */
  2216. -    register linetype *temp;
  2217. -    register long topd, botd;
  2218. -
  2219. -    if (v <= firstline->vv) {                      /* above first line */
  2220. -        if (firstline->vv - v > VERTICALEPSILON) {
  2221. -            temp = getline();
  2222. -            temp->next = firstline;
  2223. -            firstline->prev = temp;
  2224. -            temp->vv = v;
  2225. -            firstline = temp;
  2226. -        }
  2227. -        return firstline;
  2228. -    }
  2229. -
  2230. -    if (v >= lastline->vv) {                       /* below last line */
  2231. -        if (v - lastline->vv > VERTICALEPSILON) {
  2232. -            temp = getline();
  2233. -            temp->prev = lastline;
  2234. -            lastline->next = temp;
  2235. -            temp->vv = v;
  2236. -            lastline = temp;
  2237. -        }
  2238. -        return lastline;
  2239. -    }
  2240. -
  2241. -    temp = lastline;                               /* in between two lines */
  2242. -    while ((temp->vv > v) && (temp != firstline))
  2243. -        temp = temp->prev;
  2244. -
  2245. -    /* temp->vv < v < temp->next->vv --- temp is above, temp->next is below */
  2246. -    topd = v - temp->vv;
  2247. -    botd = temp->next->vv - v;
  2248. -    if ((topd < VERTICALEPSILON) || (botd < VERTICALEPSILON))
  2249. -        if (topd < botd)                           /* take best fit */
  2250. -            return temp;
  2251. -        else
  2252. -            return temp->next;
  2253. -
  2254. -    /* no line fits suitable, generate a new one */
  2255. -    currentline = getline();
  2256. -    currentline->next = temp->next;
  2257. -    currentline->prev = temp;
  2258. -    temp->next->prev = currentline;
  2259. -    temp->next = currentline;
  2260. -    currentline->vv = v;
  2261. -    return currentline;
  2262. -
  2263. -} /* findline */
  2264. -
  2265. -/*----------------------------------------------------------------------------*/
  2266. -
  2267. -unsigned long num(size)
  2268. -register int size;
  2269. -{
  2270. -    register int i;
  2271. -    register long x = 0;
  2272. -
  2273. -    for (i = 0; i < size; i++)
  2274. -        x = (x << 8) + (unsigned) getc(DVIfile);
  2275. -    return x;
  2276. -
  2277. -} /* num */
  2278. -
  2279. -
  2280. -long snum(size)
  2281. -register int size;
  2282. -{
  2283. -    register int i;
  2284. -    register long x = 0;
  2285. -
  2286. -    x = getc(DVIfile);
  2287. -    if (x & 0x80)
  2288. -        x -= 0x100;
  2289. -    for (i = 1; i < size; i++)
  2290. -        x = (x << 8) + (unsigned) getc(DVIfile);
  2291. -    return x;
  2292. -
  2293. -} /* snum */
  2294. -
  2295. -/*----------------------------------------------------------------------------*/
  2296. -
  2297. -void outchar(ch)                     /* output ch to appropriate line */
  2298. -register char ch;
  2299. -{
  2300. -    register int i, j;
  2301. -
  2302. -/*     fprintf(stderr, "hor: %ld, ver: %ld\n", h, v); */
  2303. -#if defined(MSDOS)
  2304. -    if (labs(v - currentline->vv) > VERTICALEPSILON / 2L)
  2305. -#else
  2306. -    if (abs(v - currentline->vv) > VERTICALEPSILON / 2L)
  2307. -#endif
  2308. -        currentline = findline();
  2309. -    switch (ch) {
  2310. -        case 11  :  outchar('f'); ch = 'f'; break;  /* ligature        */
  2311. -        case 12  :  outchar('f'); ch = 'i'; break;  /* ligature        */
  2312. -        case 13  :  outchar('f'); ch = 'l'; break;  /* ligature        */
  2313. -        case 14  :  outchar('f'); outchar('f');
  2314. -                                  ch = 'i'; break;  /* ligature        */
  2315. -        case 15  :  outchar('f'); outchar('f');
  2316. -                                  ch = 'l'; break;  /* ligature        */
  2317. -        case 16  :  ch = 'i'; break;
  2318. -        case 17  :  ch = 'j'; break;
  2319. -        case 25  :  outchar('s'); ch = 's'; break;  /* German double s */
  2320. -        case 26  :  outchar('a'); ch = 'e'; break;  /* Dane/Norw ae    */
  2321. -        case 27  :  outchar('o'); ch = 'e'; break;  /* Dane/Norw oe    */
  2322. -        case 28  :  if (scascii)
  2323. -                        ch = '|';                   /* Dane/Norw /o    */
  2324. -                    else
  2325. -                        ch = 'o';
  2326. -                    break;
  2327. -        case 29  :  outchar('A'); ch = 'E'; break;  /* Dane/Norw AE    */
  2328. -        case 30  :  outchar('O'); ch = 'E'; break;  /* Dane/Norw OE    */
  2329. -        case 31  :  if (scascii)
  2330. -                        ch = '\\';                  /* Dane/Norw /O    */
  2331. -                    else
  2332. -                        ch = 'O';
  2333. -                    break;
  2334. -#if 0
  2335. -        case 92  :  ch = '"'; break;                /* beginning qoute  */
  2336. -        case 123 :  ch = '-'; break;
  2337. -        case 124 :  ch = '_'; break;
  2338. -        case 125 :  ch = '"'; break;
  2339. -        case 126 :  ch = '"'; break;
  2340. -#endif
  2341. -    }
  2342. -#if 0
  2343. -    j = (int) (((double) h / (double) maxpagewidth) * (ttywidth-1)) + 1;
  2344. -#else
  2345. -    j = (int) (h / charwidth);
  2346. -#endif
  2347. -    if (j > rightmargin)
  2348. -        j = rightmargin;
  2349. -    else if (j < leftmargin)
  2350. -        j = leftmargin;
  2351. -    foo = leftmargin - 1;
  2352. -    /*-------------------------------------------------------------*/
  2353. -    /* The following is very specialized code, it handles national */
  2354. -    /* Swedish characters. They are respectively: a and o with two */
  2355. -    /* dots ("a & "o) and a with a circle (Oa). In Swedish "ASCII" */
  2356. -    /* these characters replace }{|][ and \.  TeX outputs these by */
  2357. -    /* first issuing the dots or circle and then backspace and set */
  2358. -    /* the a or o.  When dvitty finds an a or o it searches in the */
  2359. -    /* near vicinity for the character codes that represent circle */
  2360. -    /* or dots and if one is found the corresponding national char */
  2361. -    /* replaces the special character codes.                       */
  2362. -    /*-------------------------------------------------------------*/
  2363. -    if (scascii) {
  2364. -        if ((ch == 'a') || (ch == 'A') || (ch == 'o') || (ch == 'O')) {
  2365. -            for (i = IMAX(leftmargin, j-2);
  2366. -                 i <= IMIN(rightmargin, j+2);
  2367. -                 i++)
  2368. -                if ((currentline->text[i - leftmargin] == 127) ||
  2369. -                    (currentline->text[i - leftmargin] == 23))
  2370. -                    foo = i;
  2371. -            if (foo >= leftmargin) {
  2372. -                j = (int) foo;
  2373. -                switch (currentline->text[j - leftmargin]) {
  2374. -                    case 127 : if (ch == 'a')
  2375. -                                   ch = '{';
  2376. -                               else if (ch == 'A')      /* dots ... */
  2377. -                                   ch = '[';
  2378. -                               else if (ch == 'o')
  2379. -                                   ch = '|';
  2380. -                               else if (ch == 'O')
  2381. -                                   ch = '\\';
  2382. -                               break;
  2383. -                    case 23  : if (ch == 'a')
  2384. -                                   ch = '}';
  2385. -                               else if (ch == 'A')      /* circle */
  2386. -                                   ch = ']';
  2387. -                               break;
  2388. -                }
  2389. -            }
  2390. -        }
  2391. -    }
  2392. -    /*----------------- end of 'Scandinavian code' ----------------*/
  2393. -    if (foo == leftmargin-1)
  2394. -        while ((currentline->text[j - leftmargin] != SPACE)
  2395. -               && (j < rightmargin)) {
  2396. -            j++;
  2397. -            h += charwidth;
  2398. -        }
  2399. -    if ( ((ch >= SPACE) && (ch != DEL)) ||
  2400. -         (scascii && (ch == 23)) ) {
  2401. -        if (j < rightmargin)
  2402. -            currentline->text[j - leftmargin] = ch;
  2403. -        else
  2404. -            currentline->text[rightmargin - leftmargin] = '@';
  2405. -        if (j > currentline->charactercount)
  2406. -            currentline->charactercount = j;
  2407. -        if (j < firstcolumn)
  2408. -            firstcolumn = j;
  2409. -        h += charwidth;
  2410. -    }
  2411. -
  2412. -} /* outchar */
  2413. -
  2414. -/*----------------------------------------------------------------------------*/
  2415. -
  2416. -void putcharacter(charnr)            /* output character, don't change h */
  2417. -register long charnr;
  2418. -{
  2419. -    register long saveh;
  2420. -
  2421. -    saveh = h;
  2422. -    if ((charnr >= 0) && (charnr <= LASTCHAR))
  2423. -        outchar((char) charnr);
  2424. -    else
  2425. -        setchar(charnr);
  2426. -    h = saveh;
  2427. -
  2428. -} /* putcharacter */
  2429. -
  2430. -/*----------------------------------------------------------------------------*/
  2431. -
  2432. -void setchar(charnr)
  2433. -long charnr;
  2434. -{    /* should print characters with character code>127 from current font */
  2435. -     /* note that the parameter is a dummy, since ascii-chars are<=127    */
  2436. -
  2437. -    outchar('#');
  2438. -
  2439. -} /* setchar */
  2440. -
  2441. _E_O_F_
  2442. if test 31593 -ne `wc -c < dvistuff.c `; then
  2443.     echo shar: "'dvistuff.c'" unpacked with wrong size!
  2444. fi
  2445. # end of shell archive
  2446. exit 0
  2447. -- 
  2448. #########################################
  2449. # Marcel J.E. Mol                       # They hate you if your're clever
  2450. # Delft, University of Technology       # And they despise the fool
  2451. # The Netherlands                       # Till you're so fucking crazy
  2452. # UUCP: marcel@duteca.UUCP              # You can't follow the rules.
  2453. #       duteca!marcel                      #
  2454. #########################################             - Lennon
  2455.